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
19
votes
3 answers

How do you implement the factorial function in C++?

Possible Duplicates: Calculating large factorials in C++ Howto compute the factorial of x How do you implement the factorial function in C++? And by this I mean properly implement it using whatever argument checking and error handling logic is…
Jonathan Allen
  • 68,373
  • 70
  • 259
  • 447
19
votes
3 answers

How can I handle File Uploads in a Microservice Environment?

I am in the process of trying to make a decision on how, when and where to handle uploaded files from users. We are in a MicroService environment (PHP + Linux) for a new system to be deployed in the coming months. One key component is incoming…
SeaFuzz
  • 1,177
  • 9
  • 28
19
votes
2 answers

REST API design: Tell the server to "refresh" a set of resources

We have some resources on a REST server structured like this: /someResources/foo /someResources/bar /someResources/baz where someResource is a server representation of a distributed object far away. We want to tell the server to "refresh" its…
k1eran
  • 4,492
  • 8
  • 50
  • 73
19
votes
3 answers

Return data from Laravel Jobs

TL;DR: How can I return data from a queued Job without saving it anywhere and handling the situation when the job might run more than once because of retries? Or is there another way if Jobs are not suitable for this? I am developing API on Laravel…
Bushikot
  • 783
  • 3
  • 10
  • 26
18
votes
1 answer

Multiple Dtos for same entity

Is it a good practice to use multiple DTO's for same entity in different API endpoints. For example: I have a api endpoint which accpets the following Dto: public class AddressDto { public string City { get; set; } public string Country {…
Util
  • 191
  • 1
  • 5
18
votes
3 answers

Can I PUT without an ID?

I'm designing an API Rest service that allows the user to upload a file to the server. I'm thinking this is a PUT request and it would go to server/resource/ID and have the file as base64 in the json request body. My question is regarding this ID.…
David
  • 3,364
  • 10
  • 41
  • 84
18
votes
2 answers

Multithreading within a Celery Worker

I am using Celery with RabbitMQ to process data from API requests. The process goes as follows: Request > API > RabbitMQ > Celery Worker > Return Ideally I would spawn more celery workers but I am restricted by memory constraints. Currently, the…
Dominic Cabral
  • 962
  • 9
  • 21
18
votes
4 answers

Is it good practice for a website to use its own API?

Is it good practice to develop the API while developing the site so the site itself actually uses the API? Or is there a performance hit if choosing to do this? For example, does anyone know if mature sites such as Facebook or Digg use their own API…
axsuul
  • 7,370
  • 9
  • 54
  • 71
18
votes
5 answers

Why does Iterables.find() in Guava throw NoSuchElementException, instead of returning null?

I love Google Guava and use it a lot, but there is one method I always find me writing.. public static T tryFind(Iterable iterable, Predicate predicate){ for(T t : iterable){ if(predicate.apply(t)){ return t; …
Enno Shioji
  • 26,542
  • 13
  • 70
  • 109
17
votes
4 answers

Writing functions that accept both 1-D and 2-D numpy arrays?

My understanding is that 1-D arrays in numpy can be interpreted as either a column-oriented vector or a row-oriented vector. For instance, a 1-D array with shape (8,) can be viewed as a 2-D array of shape (1,8) or shape (8,1) depending on…
Joe Holloway
  • 28,320
  • 15
  • 82
  • 92
17
votes
4 answers

Default argument vs overloads in C++

For example, instead of void shared_ptr::reset() noexcept; template void shared_ptr::reset(Y* ptr); one may think of template void shared_ptr::reset(Y* ptr = nullptr); I think performance difference is negligible…
Lingxi
  • 14,579
  • 2
  • 37
  • 93
17
votes
1 answer

Why would a RESTful API send cookies with the API response?

The other day I got a strange warning in my client after sending requests to twitter: 2018-01-12 02:32:50,162 WARN o.a.h.c.p.ResponseProcessCookies:130 - Invalid cookie header: "set-cookie: guest_id=v1%3A151572431977858379; Expires=Sun, 12 Jan 2020…
Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
17
votes
1 answer

What is the point of VkApplicationInfo?

In the new Vulkan API, there is a struct which is needed to create a VkInstance: VkApplicationInfo. Here's the definition: typedef struct VkApplicationInfo { VkStructureType sType; const void* pNext; const char* …
Jerfov2
  • 5,264
  • 5
  • 30
  • 52
17
votes
3 answers

Consuming own API for web app - Authentication process with OAuth2

Overview I am currently in the process of creating an API for an image sharing app that will run on the web and sometime in the future, on mobile. I understood the logical parts of API building, but I'm still struggling to meet my own requirements…
aborted
  • 4,481
  • 14
  • 69
  • 132
17
votes
2 answers

HATEOAS links with PUT/POST

What would be the best way to represent a HATEOAS link for a POST/PUT/PATCH on a resource? These operations have payload but we won't have an option to represent the payload in HATEOAS link as they aren't predetermined and can be heavy. So would it…
g0c00l.g33k
  • 2,458
  • 2
  • 31
  • 41