Answer the question
In order to leave comments, you need to log in
How to write a service API correctly?
Hello, I need to write an API for the service.
The task seems to be clear and the question has already been asked here many times, but ... everything is more complicated here. Actually now I will share my opinion and call for a discussion thereof.
What do you want:
Answer the question
In order to leave comments, you need to log in
Did something like this recently. I got general models, processing in controllers. And by the way, already when I did it, I tried to imagine the situation that it would be necessary to make another version - it didn’t work out. All hypothetical changes fit into the current version, taking into account backward compatibility, but left the possibility of versioning.
Before writing, I studied quite a lot of literature, blogs and presentations, I even started writing an article on Habré, but so far laziness has won. The most useful thing I've read is REST API Design Rulebook , I recommend it.
Models cannot be duplicated by definition. Have you changed the data structure in the storage (for example, in the database), and you are working with the new table using the old code?
There is only one way out - to make the API from the simplest and thinnest layer of controllers as possible, and edit them when the models change. You might consider generating the API automatically, for example based on the description (CUI function name - Involved models - Transmitted fields and their mapping), if possible. From the same description, in a particularly successful scenario, it is possible to generate documentation for the API.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question