I’d say REST apis should also support selections. E.g I only care about these fields. It’s the #1 reason why graphql is so popular. You only fetch what you want. But I have missed feelings about graphql. I wish they didn’t invent a new language, it was just json. I’ve encountered so many little bugs because graphql parsing is different between different servers. Ideas of graphql are great, implementation seems over c…
> It’s the #1 reason why graphql is so popular. You only fetch what you want. It's certainly one of the main sales points for graphql. On the flip side, I've never been frustrated by getting too many fields back from an API. I suppose if I was developing exclusively in extremely bandwidth limited contexts where getting back only 2 fields rather than 50 actually made a difference, I might care. It just seems like such…
Best practices for REST API design (2020)
61–70 of 273 posts
Re: Best practices for REST API design (2020)
#62I always have mixed feelings about using plurals for naming. Pluralization in English is extremely inconsistent. cat -> cats, dog -> dogs, child -> children, person -> people, etc. It makes my code feel inconsistent too. Sometimes I use more specific typing to resolve this, e.g. PersonList , but I'm not sure that's any better.
Things are object_detail (singular) and object_list (plural).
It just assumes 'append s' for plural displays, unless you override. I like the _list suffix instead of trying to pluralize
Re: Best practices for REST API design (2020)
#63I’d say REST apis should also support selections. E.g I only care about these fields. It’s the #1 reason why graphql is so popular. You only fetch what you want. But I have missed feelings about graphql. I wish they didn’t invent a new language, it was just json. I’ve encountered so many little bugs because graphql parsing is different between different servers. Ideas of graphql are great, implementation seems over c…
You could throw static json blobs on S3 as a rest API but selections would not be supported.
Re: Best practices for REST API design (2020)
#64Earlier quoted context omitted.
So, what you are saying is reimplement graphQL.
no, what im saying is graphql is introducing something they think is novel, when it already can be done in REST. it's not hard. In my specific case, using Flask-Marshmallow i can do this ``` some_resource = Resource.find_by_id(resource_id) arg = request.args.get('type_of_resource') if arg == 'with_commments': return full_resource_schema.dump(some_resource), 200 if arg == 'no_comments': return no_comments_schema.dump(…
Re: Best practices for REST API design (2020)
#65Re: Best practices for REST API design (2020)
#66Re: Best practices for REST API design (2020)
#67I interrupted my reading at 'Accept and respond with JSON' to write this comment, before I skipped over that section and returned to reading the rest. Folks that aren't aware of Webmachine should take a look: https://github.com/webmachine/webmachine The 'Accept' header should determine the response type, but content negotiation is something that few bother to implement. Webmachine does that for you, among other thing…
Re: Best practices for REST API design (2020)
#68Small typo-ish error in the article, emphasis mine: > 401 Unauthorized – This means the user isn’t not authorized to access a resource. Surely that should say that the user isn't not unauthorised?
403 is unauthorized (forbidden due to authorization policy). 401 is unauthenticated (not logged in). Very important difference for clients handling authentication state.
Re: Best practices for REST API design (2020)
#69Re: Best practices for REST API design (2020)
#70Earlier quoted context omitted.
So, what you are saying is reimplement graphQL.
no, what im saying is graphql is introducing something they think is novel, when it already can be done in REST. it's not hard. In my specific case, using Flask-Marshmallow i can do this ``` some_resource = Resource.find_by_id(resource_id) arg = request.args.get('type_of_resource') if arg == 'with_commments': return full_resource_schema.dump(some_resource), 200 if arg == 'no_comments': return no_comments_schema.dump(…