API Documentation
Blow is a mock API documentation example with a JavaScript and GET Request.
Puppy-palooza (Mock API)
Get All the Puppies
This endpoint retrieves all the puppies.
HTTP Request
GET http://example.com/api/Puppy-palooza
Query Parameters
Get a Specific Puppy
This endpoint retrieves a specific puppy.
JavaScript
// Define the API URL
const puppy = require('puppy');
let api = puppy.authorize('woofwoof');
let puppy = api.Puppy-palooza.get();
// The above command would return JSON:
{
{
"id": 1,
"name": "Mr. Broccoli",
"breed": "Lab",
"fluffiness": 1,
"cuteness": 9
},
{
"id": 2,
"name": "Lucy",
"breed": "Corgi",
"fluffiness": 4,
"cuteness": 8
}
]
const puppy = require('puppy');
let api = puppy.authorize('woofwoof');
let max = api.Puppy-palooza.get(2);
GET Request
// Define the API URL to call
const apiUrl = 'http://example.com/api/Puppy-palooza';
// Make a GET request
fetch(apiUrl)
// .then() method handles the asynchronous response from the server.
.then(response => {
// property is checked to ensure the response is valid.
if (!response.ok) {
throw new Error('Network response was not ok');
}
// parse the JSON data using the response.json() method
return response.json();
})
.then(data => {
console.log(data);
})
// log the data to the console, or handle any errors that may occur.
.catch(error => {
console.error('Error:', error);
});