Before proceeding, let's look at what parts of an endpoint or url. For example:
- "api" is the API query subdomain.
- "company.com" is the domain of your account.
- "Daily indicators" is the name of the API. Remember that the API name would be the item you define when creating the API.
- "v1" is the API version. Review the article on versions of APIs.
- "dolar" is the name of the API method.
- ".json" is the format of consultation to the method. Review the article on output formats.
- What follows the question mark "?" are the parameters to be sent, such as auth_key or others required by the method.
Definition of language
Define a language to use for your APIs and methods. We recommend using English if it is your primary language, but you can also use English. What is relevant in this case is to be consistent, the same language should always be used for APIs, methods, attributes, dictionaries, etc.
Method route
When creating a method, you should define your route.
- Use plural nouns, not verbs.
- Avoid using singular nouns.
- Use the same routes for different types of requests.
- Do not use accents, spaces or special characters in the URL.
- If you want to separate words use the average guide.
Correct examples
Get list of documents in .json format:
- Get https://api.empresa.com/api/v1/documents.json
Obtain documents by identifier in .json format:
- Get https://api.empresa.com/api/v1/documents/123.json
Create documents
- Post https://api.empresa.com/api/v1/documents.json
Incorrect examples
Singular nouns are not recommended:
- GET https://api.empresa.com/api/v1/documents
- GET https://api.empresa.com/api/v1/document/123.json
Verbs in the URL
- POST https://ejemplo.cl/api/v1/application/create
Parameters on the route
If required, you can add the data view parameters on the method path.
By default, the method inherits the parameters of its associated view. For example:
- http://api.junar.com/accounts/v1/users.json?auth_key=XXXXX&id=16329928
But it is also possible to add a parmeter on the method path. To do this, you must enter the route to the method on behalf of the key parameter.
For example:
- /users/{id}
In this case, the API consultation would have the following structure:
- http://api.junar.com/accounts/v1/users/123.json?auth_key=XXXXX