With a few exceptions, the PetHub API is generally accessed through HTTP request methods (e.g. GET, POST, PUT, DELETE) that follow a general pattern:
https://pethub.io/v1/{noun} https://pethub.io/v1/{noun}/{id} https://pethub.io/v1/{noun}/{id}/{type}
The "v1" is simply to help us provide versioning with our APIs. That way when we start working on a version 2 will can void disrupting any applications utilizing the previous version. The {noun} is the type of resource that is being worked with and the {id} is the identifier for a specific resource being acted upon. The {type} parameter allows for a scoped search in certain situations.
Part of authenticating each request is the use of the aforementioned access token that is passed as part of the header in the request. Using cURL as an example of what this might look like, the request would look similar to the following:
curl -H "Authorization: Bearer {access_token}" GET https://pethub.io/v1/{noun}/{id}
See the documentation on Authentication for additional details about obtaining the value that would replace the {access_token} entry shown above. Also, for the sake of clarity, please note that the curly braces are a documentation preference and not literally included when substituting your actual values. For example, if your access token were "abc123" and the noun was "pets" and the individual pet's ID was 321, the statement using the above syntax would be:
curl -H "Authorization: Bearer abc123" GET https://pethub.io/v1/pets/321
Further Explanation
Exploring the above example further, let's dissect this statement to better understand it:
- curl - this is the command-line tool for transferring data (cURL)
- -H - the "-H" or "--header" option allows custom header settings to be passed to the server (in this case, we are adding in the "Authorization: Bearer abc123" string to the header as part of the request)
- GET - the HTTP method being used in this request to the server followed by the URL
If the endpoint supports parameters, those can be included as part of the URL.