Graygram Documentation¶
REST API Reference¶
REST API Overview¶
Endpoints¶
Image Request¶
Endpoint: https://www.graygram.com
-
GET
/photos/
(photo_id)/
(int: width)x
(int: height)¶ Get the binary of resized image. The value of (width) and (height) must be equal.
Error Response¶
The error response contains a json object named error
. This object contains optional message
and optional field
.
Example response:
HTTP/1.1 400 Bad Request
Content-Type: application/json
{
"error": {
"message": "Missing parameter",
"field": "username"
}
}
Authentication¶
Login¶
-
POST
/login/username
¶ Login using username and password.
Example request:
POST /login/username HTTP/1.1 Accept: application/json
Example response:
HTTP/1.1 200 OK Content-Type: application/json { "username": "devxoul", "photo": null, "created_at": "2017-02-21T16:59:35+0000", "id": 1 }
Form Parameters: - username – Username of the user
- password – Password of the user
Status Codes: - 200 OK – Succeeded to login
- 400 Bad Request – Missing or wrong parameters
Join¶
-
POST
/join/username
¶ Create a new user with username and password.
Example request:
POST /join/username HTTP/1.1 Accept: application/json
Example response:
HTTP/1.1 201 OK Content-Type: application/json { "username": "devxoul", "photo": null, "created_at": "2017-02-21T16:59:35+0000", "id": 1 }
Form Parameters: - username – Username of the user
- password – Password of the user
Status Codes: - 201 Created – Succeeded to create a new user
- 400 Bad Request – Missing or wrong parameters
- 409 Conflict – User already exists
Feed¶
-
GET
/feed
¶ Example request:
GET /feed HTTP/1.1 Accept: application/json
Example response:
HTTP/1.1 200 OK Content-Type: application/json { "data": [ { "message": "생 마르탱 운하에서 본 할머니와 할아버지", "id": 14, "is_liked": false, "like_count": 0, "user": { "created_at": "2017-02-07T09:23:13+0000", "photo": { "id": "d7394923-cf39-4c78-891a-8714eb615ea7" }, "username": "devxoul", "id": 1 }, "created_at": "2017-01-27T19:52:32+0000", "photo": { "id": "69e892b4-7dbd-403c-92fc-07f199c2be35" } }, { "message": "서울의 한 골목", "id": 13, "is_liked": false, "like_count": 0, "user": { "created_at": "2017-02-07T09:23:13+0000", "photo": { "id": "d7394923-cf39-4c78-891a-8714eb615ea7" }, "username": "devxoul", "id": 1 }, "created_at": "2017-01-27T19:52:02+0000", "photo": { "id": "1e6833e2-f041-49be-9e4a-5691d084910d" } } ], "paging": { "next": "https://www.graygram.com/feed?limit=2&offset=2" }, }
Query Parameters: - limit –
- offset –
Response JSON Object: - data (array) – Array of
Post
- paging.next (string) – (Optional) Next page URL
Post¶
Get Post¶
-
GET
/posts/
(post_id)¶ Get a single post.
Example JSON response:
{ "message": "생 마르탱 운하에서 본 할머니와 할아버지", "id": 14, "is_liked": false, "like_count": 0, "user": { "created_at": "2017-02-07T09:23:13+0000", "photo": { "id": "d7394923-cf39-4c78-891a-8714eb615ea7" }, "username": "devxoul", "id": 1 }, "created_at": "2017-01-27T19:52:32+0000", "photo": { "id": "69e892b4-7dbd-403c-92fc-07f199c2be35" } }
Response JSON Object: - id (int) –
- photo (Photo) –
- message (string) – A message (Optional)
- user (User) – Post author
- created_at (date) –
Status Codes: - 200 OK – OK
- 404 Not Found – There’s no post
Create Post¶
-
POST
/posts
¶ Create a post
Example JSON response:
{ "message": "생 마르탱 운하에서 본 할머니와 할아버지", "id": 14, "is_liked": false, "like_count": 0, "user": { "created_at": "2017-02-07T09:23:13+0000", "photo": { "id": "d7394923-cf39-4c78-891a-8714eb615ea7" }, "username": "devxoul", "id": 1 }, "created_at": "2017-01-27T19:52:32+0000", "photo": { "id": "69e892b4-7dbd-403c-92fc-07f199c2be35" } }
Form Parameters: - photo – An image file
- message – A message (Optional)
Status Codes: - 201 Created – Created
- 400 Bad Request – Required parameter is missing or invalid
- 401 Unauthorized – Not authorized
Edit Post¶
-
PUT
/posts/
(post_id)¶ Edit the post
Example JSON response:
{ "message": "생 마르탱 운하에서 본 할머니와 할아버지", "id": 14, "is_liked": false, "like_count": 0, "user": { "created_at": "2017-02-07T09:23:13+0000", "photo": { "id": "d7394923-cf39-4c78-891a-8714eb615ea7" }, "username": "devxoul", "id": 1 }, "created_at": "2017-01-27T19:52:32+0000", "photo": { "id": "69e892b4-7dbd-403c-92fc-07f199c2be35" } }
Form Parameters: - message – New message (Optional)
Status Codes: - 200 OK – OK
- 401 Unauthorized – Not authorized
- 403 Forbidden – No permission
-
PATCH
/posts/
(post_id)¶ Edit the post
Example JSON response:
{ "message": "생 마르탱 운하에서 본 할머니와 할아버지", "id": 14, "is_liked": false, "like_count": 0, "user": { "created_at": "2017-02-07T09:23:13+0000", "photo": { "id": "d7394923-cf39-4c78-891a-8714eb615ea7" }, "username": "devxoul", "id": 1 }, "created_at": "2017-01-27T19:52:32+0000", "photo": { "id": "69e892b4-7dbd-403c-92fc-07f199c2be35" } }
Form Parameters: - message – New message (Optional)
Status Codes: - 200 OK – OK
- 401 Unauthorized – Not authorized
- 403 Forbidden – No permission
Delete Post¶
-
DELETE
/posts/
(post_id)¶ Delete the post
Example JSON response:
{}
Status Codes: - 200 OK – Deleted
- 401 Unauthorized – Not authorized
- 403 Forbidden – No permission
Like Post¶
-
POST
/posts/
(post_id)/likes
¶ Like the post
Example JSON response:
{}
Status Codes: - 201 Created – Liked
- 401 Unauthorized – Not authorized
- 409 Conflict – Already liked
Unlike Post¶
-
DELETE
/posts/
(post_id)/likes
¶ Unlike the post
Example JSON response:
{}
Status Codes: - 200 OK – Unliked
- 401 Unauthorized – Not authorized
- 409 Conflict – Already unliked
User¶
Get My Profile¶
-
GET
/me
¶ Get my profile
Example JSON response:
{ "username": "devxoul", "photo": null, "created_at": "2017-02-21T16:59:35+0000", "id": 1 }
Status Codes: - 401 Unauthorized – Not authorized