V
V
Vasyl Fomin2017-08-31 23:29:04
API
Vasyl Fomin, 2017-08-31 23:29:04

How to correctly form GET requests to the API?

I am making an API for a website (website - Laravel, client - vue.js). The following questions arose related to passing parameters via GET
How best to pass an array of data, for example, for filtering, sorting...:
1. http://site.dev/api/article?a[]=1&a[]=2&a[]= 2 - so we get the ready array in GET, but the request is not very convenient
2. http://site.dev/api/article?a=1|2|3 , and then in PHP we use explode('|', '1| 2|3')
3. http://site.dev/api/article?order_by=created_at,de... again use explode
4. etc., for example, to select only the required fields from the database, for pagination.
Are there any generally accepted rules or guidelines where you can see examples?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Fetur, 2017-08-31
@Fetur

The best APIs are those that have the most intelligible and short parameters for the request.
Do not make a crutch out of the blue.
Use POST

S
Serezha, 2017-08-31
Ahen @Ahen

Better json data in the post request, in this case.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question