S
S
Sergey Sokolov2018-05-23 09:24:54
API
Sergey Sokolov, 2018-05-23 09:24:54

How to choose a protocol for an API?

The frontend of the application communicates with the backend. The format is JSON only. As you develop more and more methods and "ends" and the zoo grows:

  1. one method returns JSON with an id array or an empty array;
  2. the other returns a string of HTML markup to simply paste;
  3. the third one may refuse to answer with a message for the user “no rights to this object”, or may return the object;

It would be necessary to unify the protocol, to come to a single form in case of a normal answer or errors. Unified register of error codes. Generate a description of this protocol for third-party developers.
What are the best practices?
  • VKontakte: methods return the response load in the field response, an error if it occurs - in the field error(then it responseis absent).
  • AWS: load in response body. Errors in response status code.
  • MailChimp: Like Amazon
  • Telegram: bot api, in response to method calls, always returns the "ok" field in JSON, which has the value true or false.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
ksnk, 2018-05-23
@sergiks

First, unify the output format. You can stop only at json, or just specify the output format in the parameters - json/txt/html/xml. For json, you will need to describe and document the fields of the returned object. Whether other output formats are needed - look locally. txt can be handy for API testing and debugging.
If the project is supposed to exist for a long time, you need to add a field to the json - the "version" of the API

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question