This is a test API for Founders and Coders students to build apps with.
- Clone this repo
npm install
all dependencies- Setup environment variables (see below)
npm run dev
to start the dev server
The base URL is https://dogs-rest.herokuapp.com/v1/
.
All endpoints marked with "Authenticated" require a bearer token sent in the authorization
header. The token should be the JWT returned from either creating a new user or logging in.
Here's an example of an authenticated request using fetch
in JavaScript:
const token = "ey5a...";
fetch("https://dogs-rest.herokuapp.com/v1/users/me", {
headers: {
"content-type": "application/json",
authorization: `Bearer ${token}`,
},
}).then((user) => console.log(user));
- Authenticated
Fetch the logged in user by the access token sent in the authorization
header.
- Authenticated
Creates a new user and returns it.
{ "email": "o@o.com", "name": "oli", "password": "123" }
{ "id": 1, "email": "o@o.com", "name": "oli", "access_token": "ey5a..." }
- Authenticated
Exchange an email and password for an access_token, which should be sent to authenticate future requests. Tokens expire after 7 days.
{ "email": "o@o.com", "password": "123" }
{ "id": 1, "email": "o@o.com", "name": "oli", "access_token": "ey5a..." }
- Authenticated
Fetch every dog in the database.
[{ "id": 1, "name": "Luna", "breed": "Cocker Spaniel", "owner": 1 }]
- Authenticated
Fetch a dog by its ID.
{ "id": 1, "name": "Luna", "breed": "Cocker Spaniel", "owner": 1 }
- Authenticated
Add a new dog. Owner field will be set to the ID of the authenticated user.
{ "name": "Pongo", "breed": "Dalmation" }
{ "id": 2, "name": "Pongo", "breed": "Dalmation", "owner": 1 }
- Authenticated
Update a dog. The authenticated user must be the owner of the dog.
{ "name": "Pongo2" }
{ "id": 2, "name": "Pongo2", "breed": "Dalmation", "owner": 1 }
- Authenticated
Delete a dog. The authenticated user must be the owner of the dog.
Column | Type | Constraints |
---|---|---|
id | SERIAL | PRIMARY KEY |
VARCHAR(255) | NOT NULL | |
name | VARCHAR(255) | |
password | VARCHAR(255) |
Column | Type | Constraints |
---|---|---|
id | SERIAL | PRIMARY KEY |
name | VARCHAR(255) | |
breed | VARCHAR(255) | |
owner | INTEGER | REFERENCES users(id) |