API Documentation - dhoffmann1/Sweetiegram GitHub Wiki
heroku live-site: sweetiegram.herokuapp.com
All endpoints that require proper authorization
All endpoints that require authentication and the current user does not have the correct role(s) or permission(s).
- Request: endpoints that require proper authorization
- Error Response: Require proper authorization
-
Status Code: 403
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "Forbidden", }
-
Get the Current User
Returns the information about the current user that is logged in.
-
Require Authentication: true
-
Request
- Method: GET
- URL: /api/session
- Body: none
-
Successful Response
-
Status Code: 200
-
Headers:
- Content-Type: application/json
-
Body:
{ "id": 1, "firstName": "John", "lastName": "Smith", "email": "[email protected]", "username": "JohnSmith" }
-
Log In a User
Logs in a current user with valid credentials and returns the current user's information.
-
Require Authentication: false
-
Request
-
Method: POST
-
URL: /api/auth/login
-
Headers:
- Content-Type: application/json
-
Body:
{ "email": "[email protected]", "password": "password" }
-
-
Successful Response
-
Status Code: 200
-
Headers:
- Content-Type: application/json
-
Body:
{ "id": 1, "firstName": "John", "lastName": "Smith", "email": "[email protected]", "username": "JohnSmith", "token": "" }
-
-
Error Response: Invalid credentials
-
Status Code: 401
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "Invalid credentials", "statusCode": 401 }
-
-
Error response: Body validation errors
-
Status Code: 400
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "Validation error", "statusCode": 400, "errors": { "credential": "Email or username is required", "password": "Password is required" } }
-
Sign Up a User
Creates a new user, logs them in as the current user, and returns the current user's information.
-
Require Authentication: false
-
Request
-
Method: POST
-
URL: /api/users/signup
-
Headers:
- Content-Type: application/json
-
Body:
{ "firstName": "John", "lastName": "Smith", "email": "[email protected]", "username": "JohnSmith", "password": "secret password" }
-
-
Successful Response
-
Status Code: 200
-
Headers:
- Content-Type: application/json
-
Body:
{ "id": 1, "firstName": "John", "lastName": "Smith", "email": "[email protected]", "username": "JohnSmith", "token": "" }
-
-
Error response: User already exists with the specified email
-
Status Code: 403
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "User already exists", "statusCode": 403, "errors": { "email": "User with that email already exists" } }
-
-
Error response: User already exists with the specified username
-
Status Code: 403
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "User already exists", "statusCode": 403, "errors": { "username": "User with that username already exists" } }
-
-
Error response: Body validation errors
-
Status Code: 400
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "Validation error", "statusCode": 400, "errors": { "email": "Invalid email", "username": "Username is required", "firstName": "First Name is required", "lastName": "Last Name is required" } }
-
GET all users
-
Require authorization: true
-
Request
- Method: GET
- URL: /api/users
- Body: none
-
Successful Response
-
Status Code: 200
-
Headers:
- Content-Type: application/json
-
Body:
{ "users": [{ "id": 1, "Profile_pic_url": "picture_of_me.jpeg", "firstName": "John", "lastName": "Smith", "Username": "johnsmith01" }] }
-
GET user detail by user id
-
Require authorization: true
-
Request
- Method: GET
- URL: /api/users/int:userId
- Body: none
-
Successful Response
-
Status Code: 200
-
Headers:
- Content-Type: application/json
-
Body:
{ "user": { "id": 1, "profilePicUrl": "picture_of_me.jpeg", "firstName": "John", "lastName": "Smith", "username": "johnsmith01" "numPosts": 115, "numFollowers": 54, "numFollowing": 101, "Posts": [{ "id": 1, "post_url": "picture1.jpeg", "owner_Id": 1, "caption": "I am near the ocean!", "city": "LA", "state": "CA", "country": "US", "createdAt": "2021-11-19 20:39:36", "updatedAt": "2021-11-19 20:39:36", "numLikes": 44, "numComments": 12 }], } }
-
Posts
GET all Posts (for user)
-
Require authorization: true
-
Request
- Method: GET
- URL: /api/posts
- Body: none
-
Successful Response
-
Status Code: 200
-
Headers:
- Content-Type: application/json
-
Body:
{ posts": [{ "id": 1, "postUrl": "picture1.jpeg", "ownerId": 1, "caption": "I am near the ocean!", "city": "LA", "state": "CA", "country": "US", "createdAt": "2021-11-19 20:39:36", "updatedAt": "2021-11-19 20:39:36", "numLikes": 20, "user": { "id": 1, "firstName": "John", "lastName": "Smith", "username": "johnsmith01", "profilePicUrl": "pic.jpg" }, "comments": [{ "id": 2, "content": "nice picture!", "createdAt": "2021-11-19 20:39:36", "User": { "Id": 2, "username": "tyang2015", "profilePicUrl": "picture_of_me.jpeg", "firstName": "Tifa", "lastName": "Young", } }] }] }
-
GET a post by a Post’s ID
-
Require authorization: true
-
Request
- Method: get
- URL: /api/posts/
<int:postsid>
- Headers:
- Content-Type: application/json
- Body: none
-
Successful Response
-
Status Code: 200
-
Headers:
- Content-Type: application/json
-
Body:
{ "post": { "id": 1, "postUrl": "picture1.jpeg", "ownerId": 1, "city": "LA", "state": "CA", "country": "US", "caption": "nice landscape!" "createdAt": "2022-09-16 00:00:01" "numLikes": 20, "Comments": [{ "id": 1, "content": "This is so pretty!", "createdAt": "2022-09-16 00:00:02" "User": { "id": 3 "username": "tyang2015", "profilePicUrl": "picture_of_me.jpeg" }, }] } }
-
-
Error response: Couldn't find a Post with the specified id
-
Status Code: 404
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "Post couldn't be found", }
-
GET user posts by USER's id
-
Require authentication: true
-
Request
- Method: get
- URL: /api/users/int:user_id/posts
- Headers:
- Content-Type: application/json
- Body: none
-
Successful Response
- Status Code: 200
- Headers:
- Content-Type: application/json
- Body:
{ "posts": [{ "id": 1, "postUrl": "picture1.jpeg", "ownerId": 1, "caption": "I am near the ocean!", "city": "LA", "state": "CA", "country": "US", "createdAt": "2021-11-19 20:39:36", "updatedAt": "2021-11-19 20:39:36", "numLikes": 20, "user": { "id": 1, "firstName": "John", "lastName": "Smith", "profilePicUrl": "https://cdn.britannica.com/86/192386-050-D7F3126D/Muhammad-Ali-American.jpg?w=400&h=300&c=crop", "username": "johnsmith01" }, "comments": [{ "id": 2, "content": "nice picture!", "createdAt": "2021-11-19 20:39:36", "postId": 6, "updatedAt": "Thu, 22 Sep 2022 19:55:13 GMT", "userId": 4 "User": { "Id": 2, "username": "tyang2015", "firstName": "tiff", "lastName": "yang", "profilePicUrl": "picture_of_me.jpeg", } }] }] }
-
Error response: Couldn't find a User with the specified id
-
Status Code: 404
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "User couldn't be found", }
-
CREATE a post
-
Require authentication: true
-
Require authorization: true
-
Request
-
Method: POST
-
URL: /api/posts
-
Headers:
- Content-Type: application/json
-
Body:
{ "postUrl": "cupcake1.jpg" "city": "LA", "state": "CA", "country": "US", "caption": "nice landscape!" }
-
-
Successful Response
-
Status Code: 201
-
Headers:
- Content-Type: application/json
-
Body:
{ "id": 1, "postUrl": "cupcake1.jpg", "ownerId": 1, "caption": "I am near the ocean!", "city": "LA", "state": "CA", "country": "US", "createdAt": "2021-11-19 20:39:36", "updatedAt": "2021-11-19 20:39:36" }
-
UPDATE a post
-
Require authentication: true
-
Require authorization: true
-
Request
-
Method: PUT
-
URL: /api/posts/
<int:postsId>
-
Headers:
- Content-Type: application/json
-
Body:
{ "city": "LA", "state": "CA", "country": "US", "caption": "nice landscape! EDITED" }
-
-
Response
-
Status Code: 200
-
Headers:
- Content-Type: application/json
-
Body:
{ "id": 1, "postUrl": "newpic.jpeg", "ownerId": 1, "caption": "nice landscape! EDITED", "city": "LA", "state": "CA", "country": "US", "comments": ["awesome view!"], "numLikes": 4, "createdAt": "2021-11-19 20:39:36", "updatedAt": "2021-11-19 20:39:36" , "user": { "firstName": "Pikachu", "id": 3, "lastName": "de los Rios", "username": "detective_pikachu", "profilePicUrl": "picture_of_me.jpeg", } }
-
-
Error Response: Body validation error
-
Status Code: 400
-
Headers:
- Content-Type: application/json
-
Body:
{ "errors":['Please enter a valid url link ','Video url is invalid.', 'Image url format must be "bmp", "png", or "jpeg."' ] }
-
-
Error response: Couldn't find a Post with the specified id
-
Status Code: 404
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "Post couldn't be found", }
-
DELETE a post
-
Require authentication: true
-
Require authorization: true
-
Request
- Method: DELETE
- URL: /api/posts/
<int:postsid>
- Body: none
-
Successful Response
-
Status Code: 200
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "Successfully deleted", "statusCode": 200 }
-
-
Error response: Couldn't find a Post with the specified id
-
Status Code: 404
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "Post couldn't be found", }
-
Likes
CREATE a Like per post
-
Require auth: true
-
Request
-
Method: POST
-
URL: /api/posts/
<int:post_id>
/likes -
Body:
{ "id": 1, "postId": 1, "userId": 1 }
-
-
Successful Response
-
Status Code: 200
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "Successfully liked", "statusCode": 200 }
-
-
Error response: Already liked post
-
Status Code: 404
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "User already liked post", }
-
DELETE a Like per post
-
Require auth: true
-
Require authorization: true
-
Request
- Method: DELETE
- URL: /api/posts/
<int:postsid>
/likes - Body: none
-
Successful Response
-
Status Code: 200
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "Successfully deleted", "statusCode": 200 }
-
Comments
Get all Comments by a Post’s ID
Returns all the comments that belong to a post specified by id. Note* - User is the owner of the comment
-
Require Authentication: true
-
Request
- Method: GET
- URL: /api/posts/
<int:postsid>
/comments - Body: none
-
Successful Response
-
Status Code: 200
-
Headers:
- Content-Type: application/json
-
Body:
{ "Comments": [{ "id": 1, "postId": 1, "userId": 1, "content": "The actual review", "createdAt": "2021-11-19 20:39:36", "updatedAt": "2021-11-19 20:39:36" , "User": { "id": 1, "firstName": "John", "lastName": "Smith", "username": "johnsmith" } }] }
-
-
Error response: Couldn't find a Post with the specified id
-
Status Code: 404
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "Post couldn't be found", }
-
Create a Comment for a Post based on the Post's id
Create and return a new comment for a post specified by id.
-
Require Authentication: true
-
Request
-
Method: POST
-
URL: /api/posts/
<int:postsid>
/comments -
Headers:
- Content-Type: application/json
-
Body:
{ "content": "Nice pic!" }
-
-
Successful Response
-
Status Code: 201
-
Headers:
- Content-Type: application/json
-
Body:
{ "id": 1, "postId": 1, "userId": 1, "content": "Nice pic!", "createdAt": "2021-11-19 20:39:36", "updatedAt": "2021-11-19 20:39:36" , "User": { "id": 1, "firstName": "John", "lastName": "Smith", "username": "johnsmith", "profilePicUrl": "pic.jpg" }, }
-
-
Error Response: Body validation errors
-
Status Code: 400
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "Validation error", "statusCode": 400, "errors": { "contents": "Contents text is required" } }
-
-
Error response: Couldn't find a Post with the specified id
-
Status Code: 404
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "Post couldn't be found" }
-
Update a Comment
Update an existing comment.
-
Require Authentication: true
-
Require proper authorization: Comment must belong to the current user
-
Request
-
Method: PUT
-
URL: /api/posts/
<int:postsid>
/comments -
Body:
{ "content": "Ugly pic!" }
-
-
Successful Response
-
Status Code: 201
-
Headers:
- Content-Type: application/json
-
Body:
{ "id": 1, "postId": 1, "userId": 1, "content": "Ugly Pic", "createdAt": "2021-11-19 20:39:36", "updatedAt": "2021-11-19 20:39:36" , "User": { "id": 1, "firstName": "John", "lastName": "Smith", "username": "johnsmith", "profilePicUrl": "pic.jpg" }, }
-
-
Error response: Couldn't find a Comment with the specified id
-
Status Code: 404
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "Comment couldn't be found", "statusCode": 404 }
-
Delete a Comment
Delete an existing Comment.
-
Require Authentication: true
-
Require proper authorization: Comment must belong to the current user
-
Request
- Method: DELETE
- URL: /api/posts/
<int:postsid>
/comments/<int:commentsid>
- Body: none
-
Successful Response
-
Status Code: 200
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "Successfully deleted", "statusCode": 200 }
-
-
Error response: Couldn't find a Comment with the specified id
-
Status Code: 404
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "Comment couldn't be found", "statusCode": 404 }
-
Following
Get users that current user is following
Returns a dictionary of the people you are following. Note* - the first ‘id’ is referring to the logged in User’s id
-
Require Authentication: true
-
Request
- Method: GET
- URL: /api/user/int:id/following
- Body: none
-
Successful Response
-
Status Code: 200
-
Headers:
- Content-Type: application/json
-
Body:
{ "id": 1, "following_users": [{ "id": 1, "firstName": "John", "lastName": "Smith" "username": "johnsmith" }], "count": 55 }
-
-
Error response: Couldn't find a User with the specified id
-
Status Code: 404
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "User couldn't be found", "statusCode": 404 }
-
Add Following
Users can follow other users Note* User followers is the logged in User. User Following is the person I want to follow
-
Require Authentication: true
-
Request
-
Method: POST
-
URL: /api/user/
<int:userId>
/following -
Headers:
- Content-Type: application/json
-
Body:
{ "user_followers": 1, "user_following": 2 }
-
-
Successful Response
-
Status Code: 201
-
Headers:
- Content-Type: application/json
-
Body:
{ "id": 1, "following_users": [{ "id": 1, "firstName": "John", "lastName": "Smith" "username": "johnsmith" }], "count": 55 }
-
-
Error response: Couldn't find a User with the specified id
-
Status Code: 404
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "User couldn't be found" }
-
Delete a following
Remove / Unfollow a user
-
Require Authentication: true
-
Require proper authorization: User must belong to the current user
-
Request
- Method: DELETE
- URL: /api/user/
<int:userid>
/following - Body: none
-
Successful Response
-
Status Code: 200
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "Successfully deleted", "statusCode": 200 }
-
-
Error response: Couldn't find a User with the specified id
-
Status Code: 404
-
Headers:
- Content-Type: application/json
-
Body:
{ "message": "User couldn't be found", "statusCode": 404 }
-