Questions tagged [api-design]

API design is the process of determining and exposing a set of consistent method signatures, return values, and documentation intended for use by other developers to allow programmatic access to data.

An API (Application Programming Interface) is what developers use to work with a specific software or platform. API design refers to those practices that lead to developing a good API. A good API design helps developers leverage the full power of your platform while being easy to use. A bad API design can hinder developers from utilizing the full power of your platform and in the worst case can drive developers away from your platform because of its difficulty.

API design shares many concepts with normal programming best practices. A few of these are separation of concerns and prevention of abstraction leakage.

References

2220 questions
14
votes
4 answers

What's the best way to handle a 204 No Content response in NestJS?

I'm writing a RESTful API in Nest, which I recently started using and love so far. However, I'm struggling with finding a clean pattern to handle 204 No Content responses for my GET routes. Any recommendations? I'm a little surprised there isn't…
Eric
  • 141
  • 1
  • 1
  • 3
14
votes
2 answers

RESTful API and bulk operations

I have a middle tier which performs CRUD operations on a shared database. When I converted the product to .NET Core I thought I'd also look at using REST for the API as CRUD is supposed to be what it does well. It seems like REST is a great…
Quark Soup
  • 4,272
  • 3
  • 42
  • 74
14
votes
3 answers

Using the Rust compiler to prevent forgetting to call a method

I have some code like this: foo.move_right_by(10); //do some stuff foo.move_left_by(10); It's really important that I perform both of those operations eventually, but I often forget to do the second one after the first. It causes a lot of bugs and…
Sunjay Varma
  • 5,007
  • 6
  • 34
  • 51
14
votes
2 answers

API routes naming convention

I'm working on an API (along with an SPA) for a private project and I can't decide between two route naming conventions. Suppose I have three tables in my database : Users, Products and Orders. If I want users to be able to order products, which one…
Mickäel A.
  • 9,012
  • 5
  • 54
  • 71
14
votes
4 answers

REST API URI for resource with multiple primary keys

I am developing a generic REST API for my projects and I'm wondering what to do when I have a table/resource with 2 or more primary keys. For example, lets suppose I have a table named "question" with two primary keys (date and type) and I need to…
angro
  • 160
  • 1
  • 1
  • 7
14
votes
3 answers

Expected HTTP status code for an action on a disabled resource

What would the expected/proper HTTP status code on an action given the following: the request syntax is correct (eliminates 400) user is authenticated (eliminates 401) user is authorized to perform the action (eliminates 403) location/resource…
Jeff
  • 3,307
  • 2
  • 25
  • 36
14
votes
3 answers

Best way to create REST API for long lasting tasks?

Suppose I have 2 servers. The first is a service that provides some computations, which can last long time (minutes to hours). The second server will use this service to have some data computed. I'm trying to design a REST API for the first server…
Kugel
  • 19,354
  • 16
  • 71
  • 103
14
votes
7 answers

Is "logout" useless on a REST API?

Considering that, by definition, a REST API is stateless: is the "logout" operation useless? I mean, I'm creating a REST API using encrypted JWT. Each token has an expiration time of, let's say, 60 minutes. If I save on a database table the last…
Mario S
  • 1,914
  • 1
  • 19
  • 32
14
votes
3 answers

What is the correct way to do a get for multiple resources (batch get) with REST?

Is it: GET api/stuff?ids[]=123&ids[]=456&ids[]=789&ids[]=101112&etc... is it: POST api/stuff/batch body: ids: [123, 456, 789, 101112, etc] ? The first seems semantically correct, but aside from having an incredibly gross url, there are sources…
patrick
  • 9,290
  • 13
  • 61
  • 112
14
votes
4 answers

Safely use containers in C++ library interface

When designing a C++ library, I read it is bad practice to include standard library containers like std::vector in the public interface (see e.g. Implications of using std::vector in a dll exported function). What if I want to expose a function that…
jdm
  • 9,470
  • 12
  • 58
  • 110
13
votes
1 answer

In what scenarios are APIs that don't borrow preferred?

Rust has the concepts of ownership and borrowing. If a function doesn't borrow its parameter as a reference, the arguments to that function are moved and will be deallocated once they go out of scope. Take this function: fn build_user(email: String,…
Pascal Precht
  • 8,803
  • 7
  • 41
  • 53
13
votes
1 answer

Why do we need EPOLLRDHUP when EPOLLHUP seems enough?

According to the linux man page, EPOLLHUP When reading from a channel such as a pipe or a stream socket, this event merely indicates that the peer closed its end of the channel. EPOLLRDHUP Stream socket peer closed connection, or shut down…
xmllmx
  • 39,765
  • 26
  • 162
  • 323
13
votes
2 answers

How to handle pagination in retrofit

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…
John Hamelink
  • 1,036
  • 2
  • 15
  • 33
13
votes
3 answers

Designing an API with designated client keys

I'm designing a JSON web API and want to distinguish clients by unique IDs, in order to monitor usage and block malicious/misbehaving clients. The API is NOT encapsulated in a JavaScript library and NOT exclusive to web apps, any client type can use…
user187676
13
votes
12 answers

What's missing in Cocoa?

If you could add anything to Cocoa, what would it be? Are there any features, major or minor, that you would say are missing in Cocoa. Perhaps there is a wheel you have had to invent over and over because of an omission in the frameworks?
Bridger Maxwell
  • 2,081
  • 1
  • 19
  • 25