api-design

find-or-create idiom in REST API design?

橙三吉。 提交于 2019-12-03 22:27:01
say we have a 'user' resource with unique constraint on 'name'. how would you design a REST API to handle a find-or-create (by name) use case? I see the following options: option 1: multiple requests client: POST /user {"name":"bob"} server: HTTP 409 //or something else client: GET /user?name=bob server: HTTP 200 //returns existing user option 2: one request, two response codes client: POST /user {"name":"bob"} server: HTTP 200 //returns existing user (in case user is actually created, return HTTP 201 instead) option 3: request errs but response data contains conflicting entity client: POST

How to handle pagination in retrofit

最后都变了- 提交于 2019-12-03 17:17:44
问题 I'm building an app using retrofit. Everything's working swimmingly, but I'm worried about the size of my API requests and would like to split them up using pagination. What would be the best strategy to page through the API automatically with Retrofit, so that all available data is downloaded by default? 回答1: First, the pagination would need to be supported by the backend service that you're using. Second if you're looking to get an example of how this can be implemented from the client side

RESTful API routes design: nested vs. non-nested

只愿长相守 提交于 2019-12-03 15:50:07
问题 My question is about the advantages of nesting resources when building URLs for API purposes. Consider the following two alternatives for accessing an employee resource: /api/employees?department=1 # flat Vs. /api/departments/1/employees # nested Now consider the task of developing a general purpose library to access REST resources from an API. If all routes were flat, such a REST wrapper library would only need to know the name of the resource being accessed: store.query('employees',

Identify item by either an ID or a slug in a RESTful API

喜你入骨 提交于 2019-12-03 10:45:13
问题 I'm currently designing an API and I came a cross a little problem: How should a URL of a RESTful API look like when you should be able to identify an item by either an ID or a slug? I could think of three options: GET /items/<id> GET /items/<slug> This requires that the slug and the ID are distinguishable, which is not necessarily given in this case. I can't think of a clean solution for this problem, except you do something like this: GET /items/id/<id> GET /items/slug/<slug> This would

How “store” REST archetype isn't creating a new resource and a new URI?

时光怂恿深爱的人放手 提交于 2019-12-03 08:07:18
REST API design indicates there are four resources archetypes: document, collection, store and controller. Store do not create new resources; therefore a store never generates new URIs. An example: PUT /users/12245/favorites/boston-celtics A user added Boston Celtics to his favorites list. But how that isn't creating a new resource ? and how it isnt generating a new URI? A store does not create a resource on its own. The user of the store creates endpoints / URIs. The contrast is between a Collection and a Store Collection A collection resource is a server-managed directory of resources.

Open-source / free universal EPG / XMLTV data API or service, or how to make one? [closed]

不羁岁月 提交于 2019-12-03 06:17:05
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I am looking for (an open-source, aka "free") data-source for universal EPG / XMLTV services? The project needs updated/updateable real-time TV scheduling info, in an easily parsable format. It also MUST be available at no cost or a VERY liberal license. Thanks for any advice or alternatives. I am open to coding

How to handle pagination in retrofit

穿精又带淫゛_ 提交于 2019-12-03 06:15:16
I'm building an app using retrofit. Everything's working swimmingly, but I'm worried about the size of my API requests and would like to split them up using pagination. What would be the best strategy to page through the API automatically with Retrofit, so that all available data is downloaded by default? First, the pagination would need to be supported by the backend service that you're using. Second if you're looking to get an example of how this can be implemented from the client side using retrofit I would recommend you take a look at the u2020 project from @JakeWharton. The GalleryService

RESTful API routes design: nested vs. non-nested

こ雲淡風輕ζ 提交于 2019-12-03 05:20:40
My question is about the advantages of nesting resources when building URLs for API purposes. Consider the following two alternatives for accessing an employee resource: /api/employees?department=1 # flat Vs. /api/departments/1/employees # nested Now consider the task of developing a general purpose library to access REST resources from an API. If all routes were flat, such a REST wrapper library would only need to know the name of the resource being accessed: store.query('employees', {department_id:1}) => /api/employees?department=1 However, if we were to support nested routes, this wrapper

Using annotation to ensure that value returned by method is not discarded

你。 提交于 2019-12-03 03:38:18
问题 String in Java is immutable. The following snippet is, broadly speaking, "wrong". String s = "hello world!"; s.toUpperCase(); // "wrong"!! System.out.println(s); // still "hello world!"!!! Despite this being "wrong", the code compiles and runs, perhaps to the confusion of many beginners, who must either be told what the mistake is, or to find out for themselves by consulting the documentation. Reading the documentation is an essential part of understanding an API, but I'm wondering if this

When is an API overengineered? [closed]

▼魔方 西西 提交于 2019-12-03 02:51:58
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . I despise working with overengineered APIs that don't make simple things simple. Nonetheless, I'm working on designing an API for an