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
23
votes
14 answers

Is there a concise opposite of "empty"?

Interfaces to string classes typically have of method named IsEmpty (VCL) or empty (STL). That's absolutely reasonable because it's a special case, but the code that uses these methods often has to negate this predicate, which leads to a "optical…
Wolf
  • 9,679
  • 7
  • 62
  • 108
22
votes
5 answers

How should I build a good (web) API

I'm going to build an API for a web app and I'm interested in what people can suggest as good practices. I'm already planning to make it versioned (version 1 can only control certain aspects of the system, version 2 could control more, but this may…
Cebjyre
  • 6,552
  • 3
  • 32
  • 57
22
votes
4 answers

How should a RESTful service expose read-only properties on mutable resources?

I am working on designing a resource for this service which has a set of mutable properties and a set of immutable ones (for example, status which is generated by the service and not something the client may change). I need to include this in…
ehdv
  • 4,483
  • 7
  • 32
  • 47
21
votes
7 answers

C API design: what to do when malloc returns NULL?

Let's say I'm writing a little library in C -- some data structure, say. What should I do if I'm unable to allocate memory? It might be pretty important, e.g. I need some memory to initialize the data structure in the first place, or I'm inserting…
Ismail Badawi
  • 36,054
  • 7
  • 85
  • 97
21
votes
2 answers

API Authentication for PWA

The Setup We’re building a PWA (progressive web app). The main components are the app shell (SPA) and the API. The REST API will supply the data needed for the app, while the SPA will handle the rest (as per Google recommendation). The…
21
votes
5 answers

Should Health Checks call other App Health Checks

I have two API's A and B that I control and both have readiness and liveness health checks. A has a dependency on B. A /foo - This endpoint makes a call to /bar in B /status/live /status/ready B /bar /status/live /status/ready Should the readiness…
21
votes
1 answer

REST API Architecture: How to Represent Joined Tables

Question I have a complex query that joins three tables and returns a set of rows with each row having data from it's sibling tables. How is it possible to represent this in a RESTful way? FWIW I know there is not necessarily a "right" way to do it,…
Mike Fleming
  • 2,593
  • 4
  • 14
  • 24
21
votes
2 answers

Inheritance and Polymorphism in REST API Modeling

I have an object hierarchy that I want to expose through a REST API, and I want to discuss best practices. I have seen this question asked before (e.g. here at the end, here, here, and especially here), but never really any conclusions arrived…
emft
  • 376
  • 1
  • 2
  • 11
21
votes
2 answers

Rest api design: POST to create with duplicate data, would-be IntegrityError/500, what would be correct?

I have a normal, basic REST api like: / GET - list POST - create / GET - detail PUT - replace PATCH - patch DELETE - delete When a POST comes in to /, I usually create an object and make a new id. Some (one) of the…
Skylar Saveland
  • 11,116
  • 9
  • 75
  • 91
20
votes
3 answers

Access token vs username/password for API request

I know this might seem like a trivial question but I can't find the answer for it to at least put my mind at peace. If a mobile app is communication with a server then typically they sign in and they get an access token that they can use for the…
Snake
  • 14,228
  • 27
  • 117
  • 250
20
votes
2 answers

Tweepy - Exclude Retweets

Ultimate goal is to use the tweepy api search to focus on topics (i.e docker) and to EXCLUDE retweets. I have looked at other threads that mention excluding retweets but they were completely applicable. I have tried to incorporate what I've learned…
hansolo
  • 903
  • 4
  • 12
  • 28
20
votes
4 answers

Is an API endpoint that differentiates what resources to return based on user credentials RESTful and good URI design?

Important note The focus of this question is on API endpoints that differentiate which resources are returned depending who authenticates, e.g. Alice gets resource A and B returned, and Bob gets resource X and Y. It is NOT about differentiating…
Visionscaper
  • 3,979
  • 1
  • 23
  • 26
20
votes
5 answers

Is it acceptable to return unmodifiableList or should I return array?

I have method List getFoos () which gets the data from remote server and returns it. Of course, user shouldn't change number of items of the list because he'll get data not synchronized with data on the server (and if he want change number of…
Roman
  • 64,384
  • 92
  • 238
  • 332
19
votes
5 answers

Why is DialogResult a nullable bool in WPF?

Can anyone think of a good explanation for the fact that result of a dialog is a nullable bool in WPF? This has always baffled me. In WinForms it was an enum type and that made a lot more sense to me.
PeterAllenWebb
  • 10,319
  • 3
  • 37
  • 44
19
votes
5 answers

How do you set up an API key system for your website?

Let say that I have a website with some information that could be access externally. Those information need to be only change by the respected client. Example: Google Analytic or WordPress API key. How can I create a system that work like that (no…
Patrick Desjardins
  • 136,852
  • 88
  • 292
  • 341