This repo is meant to be used with the Mod 2 Network Request lesson plan.
git clone
the repo- cd into the cloned repo
- run
npm install
- run
npm start
. The server should be running locally on port 3001 - Navigate to the endpoint you're trying to request in the browser (ie if you want to GET users, navigate to http://localhost:3001/api/v1/users in the browser)
- Practice making your network requests in the console!
In the client
directory, there are some files we can use as a makeshift client.
- run
open client/index.html
from your command line - open your console, so that you can check your fetch requests using either
debugger
orconsole.log()
("so fetch!" should be showing up in your console on page load.) - follow the directions in
client/index.js
to practice fetching! (feel free to get rid of the gif if it's too distracting)
Follow the directions that are commented out in client/index.js
.
The following endpoints are documented below:
- GET all users
- POST a new user (you can verify this worked with another GET request)
- GET all animals
- POST a new animal
- GET all sports teams
- POST a new sports team
url | verb | options | sample response |
---|---|---|---|
http://localhost:3001/api/v1/users |
GET | not needed | Array of all existing users: [{ id: 1, name: 'Travis Rollins', status: 'online', interests: 'Music, Software, & Gaming' }] |
http://localhost:3001/api/v1/users |
POST | { id: <Number>, name: <String>, status: <String>, interests: <String> } |
New user: { id: 1, name: 'Leta', status: 'online', interests: 'Science, Music, & Classic Films' } |
url | verb | options | sample response |
---|---|---|---|
http://localhost:3001/api/v1/animals |
GET | not needed | Array of all existing animals: [{ id: 3, name: 'orcas', diet: 'birds, squid, octopuses, sea turtles, sharks, rays & fish', fun_fact: 'Orcas, also known as killer whales, are known to prey on other marine mammals, including dolphins and seals.' }] |
http://localhost:3001/api/v1/animals |
POST | { id: <Number>, name: <String>, diet: <String>, fun_fact: <String> } |
New animal: { id: 4, name: 'tigers', diet: 'chital, sambar, gaur & wild board', fun_fact: 'The main food of tigers are buffalos, antelopes, and rodents.' } |
url | verb | options | sample response |
---|---|---|---|
http://localhost:3001/api/v1/sport-teams |
GET | not needed | Array of all existing sport teams: [{ id: 1, name: 'Dallas Cowboys', head_coach: 'Jason Garrett', sport: 'football' }] |
http://localhost:3001/api/v1/sport-teams |
POST | { id: <Number>, name: <String>, head_coach: <String>, sport: <String> } |
New sport team: { id: 2, name: 'New York Yankees', head_coach: 'Aaron Boone', sport: 'baseball' }, |