E
E
Eugene2018-05-21 12:27:39
JSON
Eugene, 2018-05-21 12:27:39

How to organize getting a list of valid parameter values ​​from the API?

Hi
Need to design an API.
Prompt, how to transfer to the client the list of possible values ​​of some fields?
For example:
The "ACCOUNT" object has a "STATUS" property with the values ​​paid/partially paid/cancelled and so on.
[{
"id":1,
"sum": 100,
"status": "paid",
"items": [
{
"id": 1,
"name": "Donut",
"price": 50,
"quantity ": 2
}
]
}]
An HTML form must be generated on the client to edit account data. The account status must be selected from the list of available values.
So far I see several options:
1) Describe all possible values ​​in the API documentation. This will fix the list of available values ​​on the client. Minus - when adding a new status, you need to change the client code.
2) Provide an API for getting a list of statuses (/v1/invoices/statuses, /v1/invoices/1/statuses). The client separately downloads account data and status data separately.
Do you know any API examples where this situation is somehow solved? Tell us about your experience.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
chromimon, 2018-05-21
@chromimon

HATEOAS, Swagger, OpenAPI, OpenAPI editor, Swagger editor

A
AlexRas, 2018-05-21
@AlexRas

You check the availability of values ​​in the api and describe them in the documentation. The easiest way.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question