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
0
votes
0 answers

Ensure startup/init function is called before any function in API

I'd like to create an API somewhat along the lines of this: const myAPI = { sendMessage: (message) => { websocket.send(message) } subscribe: (subject) => { websocket.subscribe(subject) } } I'd like to have an initialization function…
0
votes
1 answer

The same validation for multiple views in django rest framework

I have created a number of API endpoints for accepting POST requests using DjangoRestFramework. For 5/6 of them, I need to have 1 key in the body present providing some data so for each view I have if (key not in request.data): return…
Umer
  • 21
  • 2
  • 5
0
votes
1 answer

REST API: endpoint name conflicts and prefixes / namespaces / logical scopes in endpoint paths

Normally I expose endpoints in this way: /api/1/users /api/1/users/{uid} /api/1/groups /api/1/groups/{gid} /api/1/items /api/1/items/{iid} To represent hierarchy I usually go this way: /api/1/groups/{gid}/users /api/1/users/{uid}/items Or to get…
Lee Mon
  • 1
  • 1
0
votes
1 answer

Should a RESTful API's payload model decide the way the api should behave?

Say I have a task entity modelled in my application as { id: "qweqdsad", name:"Drink Coffee", description:"Coffee helps in overcoming laziness", userId:12 } Now in my application, say the above JSON is the payload for create task…
Karthik
  • 629
  • 2
  • 8
  • 12
0
votes
1 answer

Is it a REST good/bad practice to pass database constraints in the response model

Let say I have data model called User and another Called UserType. And I can only delete an UserType if the type is not used in any User entry in the user table. Now when I fetch the UserType details do I fetch the constraints also that this…
Mustafa Mamun
  • 2,591
  • 2
  • 14
  • 17
0
votes
1 answer

API design - Optional body in client request - Status code to return if validation fails

In our API, one of the endpoint will expect clients to provide body/payload only in certain scenario. If the API is unable to generate a payload for given request based on the origin of the client then, we want our API to provide response with the…
VinothNair
  • 614
  • 1
  • 7
  • 24
0
votes
1 answer

Does Cache work in an API route and should we use it?

I am creating an API. In this API I am accessing a (permissions) table from a database multiple times, in middleware as well as in controllers. I was thinking, instead of accessing the database multiple times, why don't I call it once and use it…
Skeletor
  • 3,201
  • 4
  • 30
  • 51
0
votes
1 answer

Advice on designing a RESTful API for a simple ticket system

Lately I have started learning Go. In order to practice my newly acquired skills, I decided to start a small side project. In this project I want to design and build a RESTful API for a ticket system. Since I'm still quite new to this topic, I'm…
0
votes
1 answer

Having a body on a delete request as an additional layer of security

I'm developing an web API and I'm trying to follow the principles of REST. I'm now at the stage of creating the endpoint where a user can delete its own account. I have also implemented JWT functionality where the JWT is valid for 1 day. I want to…
Slamdunk
  • 424
  • 1
  • 8
  • 20
0
votes
1 answer

using a POST route when linking a resource to another one

So let's say you have two entities Product and Category. One product can have multiple categories and one category can have multiple products. When it comes to the API design you want to create endpoints to add / remove categories from a product.…
Question3r
  • 2,166
  • 19
  • 100
  • 200
0
votes
0 answers

What is the point of the return value of HashAlgorithm.TransformFinalBlock?

HashAlgorithm.TransformFinalBlock is used as the final step to generate a hash. It returns a byte array which is documented as follows: An array that is a copy of the part of the input that is hashed. Note that the return value of this method is…
boot4life
  • 4,966
  • 7
  • 25
  • 47
0
votes
1 answer

REST-API-Design with multiple Endpoints for one Resource

I'm currently designing a REST-API. Let's say I want to GET/POST/PUT/DELETE the following object(s) Let's say I have the following informations which I want to GET/PUT/POST/DELETE (This is just a small example. The real object has some more…
Tomtom
  • 9,087
  • 7
  • 52
  • 95
0
votes
0 answers

How to protect your own api so only your app can use it?

I am looking for a way to authorize my app's api so that only requests from my app will be accepted. For example i don't want anyone to be able to send a bunch of request to "/register" to register bot users. or Anybody to build their own app that…
Tembero
  • 387
  • 3
  • 11
0
votes
1 answer

Rest API Design - Image tagging application

I am working on a tagging application to explore REST and Dropwizard. Images can be uploaded and associated with tags. CRUD operation on those resources. Here the 2 resources are - image and tag. I am following the collections pattern in designing…
bong_coder
  • 11
  • 2
0
votes
3 answers

REST APIs: Hiding surrogate keys and only exposing natural keys to the user

Suppose we're working with a database that has the following relation: CREATE TABLE Author ( first_name VARCHAR NOT NULL, last_name VARCHAR NOT NULL, birth_date DATE NOT NULL, death_date DATE, biography TEXT, UNIQUE(first_name,…