I am relatively new to the environment of professional use of API Routes, so a basic question.
Im working with VueJS asFrontend and node Express as Backend. How the GET Request against the api have to look like? I wonder how to deliver filter requests with a REST API?
Example:
GET https://example.com/api/v1/cities
-> get all cities.
GET https://example.com/api/v1/cities?country={countrId}
-> get all cities from this country with the id = {countrId}.
Question: Is this an API antipattern? If so, what would the route look like?
Note: A colleague told me it should look like this:
GET https://example.com/api/v1/cities?country.id={countrId}
CodePudding user response:
If you want to set just id
, then url could look like this:
https://example.com/api/v1/cities/1
Read more about API best practices here
If you have many query string parameters, then it could look like this:
https://example.com/api/v1/cities?id=1&location=foo&lang=bar