Back end repository for: co-make-3
Base url: http://co-make-3.herokuapp.com/
http type | endpoint | category | payload |
---|---|---|---|
post | /api/auth/register | auth | yes |
post | /api/auth/login | auth | yes |
http type | endpoint | category | payload |
---|---|---|---|
get | /api/users/:id | user by id | no |
put | /api/users/:id | edit user | yes |
delete | /api/users/:id | delete user | no |
http type | endpoint | category | payload |
---|---|---|---|
get | /api/posts | all posts | no |
get | /api/posts/comments | posts w/ comments | no |
get | /api/posts/:id | post by id | no |
get | /api/posts/by/user | posts by user | no |
post | /api/posts | add post | yes |
put | /api/posts/:id | edit post | yes |
delete | /api/posts/:id | delete post | no |
http type | endpoint | category | payload |
---|---|---|---|
post | /api/posts/city | posts by city | yes |
post | /api/posts/zipcode | posts by zip_code | yes |
http type | endpoint | category | payload |
---|---|---|---|
post | /api/posts/:id/increment/votes | increase votes | no |
http type | endpoint | category | payload |
---|---|---|---|
get | /api/posts/:id/comments | all comments for one post | no |
post | /api/posts/:id/comments | add comment to post | yes |
put | /api/comments/:id | edit comment | yes |
delete | /api/comments/:id | delete comment | no |
POST /api/auth/register
Required fields: username, password, first_name, last_name, email
Optional Fields: profile_image_url, government_official (boolean)
Expected Request Body:
{
"username": "user1",
"password": "password",
"first_name": "Patrick",
"last_name": "Replogle",
"email": "user1@gmail.com",
"profile_image_url": "http://www.image_url.com"
}
Returns:
{
"new_user": {
"id": 1,
"username": "user1",
"first_name": "Patrick",
"last_name": "Replogle",
"email": "user1@email.com",
"profile_image_url": "http://www.image_url.com",
"government_official": 0
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyaWQiOjQsInVzZXJuYW1lIjoiRGVtbzUiLCJpYXQiOjE1NzY4MDg1OTgsImV4cCI6MTU3NjgxMjE5OH0.PCNRX9Wn16kFBrTDNdQtHlyqs8BbiLxvAXvJHXDokzM"
}
POST /api/auth/login
Expected Request Body:
{
"username": "user1",
"password": "password"
}
Returns:
{
"id": 1,
"username": "user1",
"message": "Welcome user1!",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MiwidXNlcm5hbWUiOiJ1c2VyMiIsImlhdCI6MTU4MjU2NTg1NSwiZXhwIjoxNTgzMTcwNjU1fQ.co-vWFadM3IbKznIUVsbyZkOqv7A1h1evS4jIsGpokA"
}
GET /api/users/:id
Returns:
{
"id": 1,
"username": "user1-edited",
"first_name": "Patrick",
"last_name": "Replogle",
"email": "user1@gmail.com",
"profile_image_url": "http://www.image_url.com"
}
PUT /api/users/:id
Expected Request Body:
{
"username": "user1-edited",
"password": "password",
"first_name": "Patrick",
"last_name": "Replogle",
"email": "user1@gmail.com",
"profile_image_url": "http://www.image_url.com"
}
Returns:
{
"id": 1,
"username": "user1-edited",
"first_name": "Patrick",
"last_name": "Replogle",
"email": "user1@gmail.com",
"profile_image_url": "http://www.image_url.com"
}
DELETE /api/users/:id
Returns:
{
message: "User account successfully deleted",
removed: 1
}
GET /api/posts
GET /api/posts/comments
GET /api/posts/:id
GET /api/posts/by/user
Required fields: title, description, city, zip_code
optional fields: post_image_url
POST /api/posts
Expected Request Body:
{
"title": "new post",
"description": "stuff needs to be fixed",
"city": "Portland",
"zip_code": "97206",
"post_image_url": "www.image.com"
}
8000
code>
Returns:
{
"id": 5,
"title": "new post",
"description": "stuff needs to be fixed",
"post_image_url": "www.image.com",
"city": "Portland",
"zip_code": "97206",
"user_id": 1,
"votes": 0,
"authorUsername": "user1",
"authorEmail": "fakeuser1@gmail.com"
}
Same required/optional fields as adding a post
PUT /api/posts/:id
DELETE /api/posts/:id
POST /api/posts/city
required fields: city (not case sensitive)
Expected Request Body:
{
"city": "portland"
}
POST /api/posts/zipcode
required fields: zip_code
Expected Request Body:
{
"zip_code": "97219"
}
No need to add a payload/body to this request
POST /api/posts/:id/increment/votes
GET /api/posts/:id/comments
Required fields: text
POST /api/posts/:id/comments
Expected Request Body:
{
"text": "new comment"
}
Returns:
{
"id": 9,
"text": "new comment",
"username": "user1",
"post_id": 4,
"user_id": 1
}
Required fields: text
PUT /api/comments/:id
{
"text": "edited comment"
}
Returns:
{
"id": 4,
"text": "edited comment",
"username": "user1",
"post_id": 3,
"user_id": 1
}
DELETE /api/comments/:id