The endpoint is the URL you send a request to. It is made up of three parts:
- The root
- The path
- Query parameters
Here’s an example of an endpoint that contains all three parts.
https://api.github.com/users/zellwk/repos?per_page=100
Root
The root (or root endpoint) is the origin of the API.
The origin contains three things:
- A Protocol (the
file://,http://orhttps://part) - A Host (the domain name)
- A Port (the number that comes after the domain name
# Example of originshttps://zellwk.comhttps://students.magicaldevschool.comhttps://api.github.comhttp://locahost:3000Each API will only have one root.
Path
The path is the part that comes after the root, but before ? (if any).
You can think about paths in the same way you would think about files and folders on your computer.
If you have folder a called blog and a file called article inside that folder, the path to this article file would be:
project-folder/blog/articleHere:
project-folderis the root/blog/articleis the path.
Each path lets you fetch a unique resource.
- The following path lets you fetch my repositories from GitHub.
- Other paths will fetch other things.
https://api.github.com/users/zellwk/reposQuery Parameters
Query parameters are key-value pairs that let you change the parameters of a response.
- Query parameters always begin with a
?. - You use
=to define the key-value pair of the parameter. - You use
&to specify another query parameter.
Here’s what they look like:
?query1=value1&query2=value2Query parameters will be listed in the documentation (next to information about the path) if they are available.
For example, here are the available parameters for fetching a user’s repositories on GitHub.
By default, Github returns 30 repositories. You can change the number of repositories returned by adding a per_page query parameter.
https://api.github.com/users/zellwk/repos?per_page=100Welcome! Unfortunately, you don’t have access to this lesson. To get access, please purchase the course or enroll in Magical Dev School.
Unlock this lesson