An API built for my to do list app. This project is for General Aseembly WDI project 2.
It has authentication, allowing the user to sign in, sign out, sign up, and change password.
The API will allow for the creation of new list items, editing existing list items, deleting list items, and will get all the list items for the associated user when they sign in.
- Ruby
- Rails
- curl
- Postman
Link to the front end repository here
| Verb | URI Pattern | Controller#Action |
|---|---|---|
| POST | /sign-up |
users#signup |
| POST | /sign-in |
users#signin |
| DELETE | /sign-out/:id |
users#signout |
| PATCH | /change-password/:id |
users#changepw |
| GET | /items |
items#index |
| POST | /items |
items#create |
| PATCH | /games/:id |
items#update |
| DELETE | /items/:id |
items#destroy |
All data returned from API actions is formatted as JSON.
Summary:
| Request | Response | |||
|---|---|---|---|---|
| Verb | URI | body | Status | body |
| POST | `/sign-up` | credentials | 201, Created | user |
| 400 Bad Request | empty | |||
| POST | `/sign-in` | credentials | 200 OK | user w/token |
| 401 Unauthorized | empty | |||
| DELETE | `/sign-out/:id` | empty | 201 Created | empty |
| 401 Unauthorized | empty | |||
| PATCH | `/change-password/:id` | passwords | 204 No Content | user w/token |
| 400 Bad Request | empty | |||
The create action expects a POST of credentials identifying a new user to
create.
```json
{
"credentials": {
"email": "an@example.email",
"password": "an example password",
"password_confirmation": "an example password"
}
}
The signin action expects a POST with credentials identifying a previously
registered user.
{
"credentials": {
"email": "an@example.email",
"password": "an example password"
}
}If the request is successful, the response will have an HTTP Status of 200 OK,
and the body will be JSON containing the user's id, email, and the token
used to authenticate other requests.
{
"user": {
"id": 1,
"email": "an@example.email",
"token": "an example authentication token"
}
}If the request is unsuccessful, the response will have an HTTP Status of 401 Unauthorized, and the response body will be empty.
The signout actions is a DELETE specifying the id of the user to sign out.
If the request is successful the response will have an HTTP status of 204 No Content.
If the request is unsuccessful, the response will have a status of 401 Unauthorized.
The changepw action expects a PATCH of passwords specifying the old and
new.
If the request is successful the response will have an HTTP status of 204 No Content.
If the request is unsuccessful the reponse will have an HTTP status of 400 Bad Request.
The sign-out and change-password requests must include a valid HTTP header
Authorization: Token token=<token> or they will be rejected with a status of
401 Unauthorized.
All items action requests must include a valid HTTP header `Authorization: Token token=
Summary:
| Request | Response | |||
|---|---|---|---|---|
| Verb | URI | body | Status | body |
| POST | `/items` | item | 200, OK | item w/ id |
| 400 Bad Request | empty | |||
| PATCH | `/items/:id` | item | 200 OK | item w/ id |
| 422 Unprocessable Entity | empty | |||
| DELETE | `/items/:id` | empty | 204 no content | empty |
| 401 Unauthorized | empty | |||
| GET | `/items/ | item | 200 OK | Items for signed in user |
| 400 bad request | ||||
The index action is a GET that retrieves all the items associated with a
user.
The response body will contain JSON containing an array of items, e.g.:
{
"items": [
{
"content": "Item 1",
"id": 43
},
{
"content": "Item 2",
"id": 3
}
]
}The create action expects a POST
Example JSON
{
"item": {
"content": "Item Content"
}
}If the request is successful, the response will have an HTTP Status of 200 OK, and the body will contain JSON of the Item and its id.
{
"item": {
"content": "Item Content",
"id": 48
}
}If the request is unsuccessful, the response will have an HTTP Status of 400 Bad Request, and the response body will be JSON describing the errors.
The destroy actions is a DELETE specifying the id of the list item to delete.
If the request is successful the response will have an HTTP status of 204 No Content.
If the request is unsuccessful, the response will have a status of 401 Unauthorized.
The update action is a PATCH specifying the id of the list item to edit.
Eample JSON
{
"item": {
"content": "item content"
}
}If the request is successful, the response will have an HTTP Status of 200 OK, and the body will contain JSON of the Item and its id.
{
"item": {
"content": "Item Content",
"id": 48
}
}If the request is unsuccessful the reponse will have an HTTP status of 422 Unprocessable Entity