An API for ember-example-listr
Install with bundle install
.
- Clone this repository.
- Install dependencies with
bundle install
. - Make new
development
andtest
secrets forconfig/secrets.yml
. Add and commit this file. - Setup your database with
bin/rake db:nuke_pave
orbundle exec rake db:nuke_pave
. - Run the API server with
bin/rails server
orbundle exec rails server
.
Developers should run these often!
rake routes
lists the endpoints available in your API.rake test
runs automated tests.rails console
opens a REPL that pre-loads the API.rails db
opens your database client and loads the correct database.rails server
starts the API.scripts/*.sh
run variouscurl
commands to test the API. See below.
Verb | URI Pattern | Controller#Action |
---|---|---|
GET | /lists |
lists#index |
GET | /lists/:id |
lists#show |
POST | /lists |
lists#create |
PATCH | /lists/:id |
lists#update |
DELETE | /lists/:id |
lists#destroy |
Request:
curl --include --request GET http://localhost:3000/lists
Response:
[
{
"id": 1,
"title": "Favorite Things",
"hidden": false,
"items": [
1,
2,
3,
4,
5
]
},
{
"id": 2,
"title": "Todo",
"hidden": false,
"items": [
6,
7
]
}
]
Request:
curl --include --request GET http://localhost:3000/lists/$ID
Response:
{
"id": 1,
"title": "Favorite Things",
"hidden": false,
"items": [
1,
2,
3,
4,
5
]
}
Request:
curl --include --request POST http://localhost:3000/lists \
--header "Content-Type: application/json" \
--data '{
"list": {
"title": "Groceries",
"hidden": false
}
}'
Response:
{
"id": 3,
"title": "Groceries",
"hidden": false,
"items": []
}
Request:
curl --include --request PATCH http://localhost:3000/lists/$ID \
--header "Content-Type: application/json" \
--data '{
"list": {
"hidden": true
}
}'
Response:
HTTP/1.1 204 No Content
Request:
curl --include --request DELETE http://localhost:3000/lists/$ID
Response:
HTTP/1.1 204 No Content
Verb | URI Pattern | Controller#Action |
---|---|---|
GET | /lists/:list_id/items |
items#index |
GET | /items/:id |
items#show |
POST | /lists/:list_id/items |
items#create |
PATCH | /items/:id |
items#update |
DELETE | /items/:id |
items#destroy |
Request:
curl --include --request GET "http://localhost:3000/lists/$LIST_ID/items"
Response:
[
{
"id": 1,
"content": "Cats",
"done": false,
"list": 1
},
{
"id": 2,
"content": "Star Wars",
"done": false,
"list": 1
},
// ...
]
Request:
curl --include --request GET http://localhost:3000/items/$ID
Response:
{
"id": 1,
"content": "Cats",
"done": false,
"list": 1
}
Request:
curl --include --request POST http://localhost:3000/items \
--header "Content-Type: application/json" \
--data '{
"item": {
"content": "Coding",
"done": false,
"list_id": 1
}
}'
Response:
{
"id": 8,
"content": "Coding",
"done": false,
"list": 1
}
Request:
curl --include --request PATCH http://localhost:3000/items/$ID \
--header "Content-Type: application/json" \
--data '{
"item": {
"done": true,
}
}'
Response:
HTTP/1.1 204 No Content
Request:
curl --include --request DELETE http://localhost:3000/items/$ID
Response:
HTTP/1.1 204 No Content
Verb | URI Pattern | Controller#Action |
---|---|---|
POST | /sign-up |
users#signup |
POST | /sign-in |
users#signin |
PATCH | /change-password/:id |
users#changepw |
DELETE | /sign-out/:id |
users#signout |
Request:
curl --include --request POST http://localhost:3000/sign-up \
--header "Content-Type: application/json" \
--data '{
"credentials": {
"email": "an@example.email",
"password": "an example password",
"password_confirmation": "an example password"
}
}'
scripts/sign-up.sh
Response:
HTTP/1.1 201 Created
Content-Type: application/json; charset=utf-8
{
"user": {
"id": 1,
"email": "an@example.email"
}
}
Request:
curl --include --request POST http://localhost:3000/sign-in \
--header "Content-Type: application/json" \
--data '{
"credentials": {
"email": "an@example.email",
"password": "an example password"
}
}'
scripts/sign-in.sh
Response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"user": {
"id": 1,
"email": "an@example.email",
"token": "33ad6372f795694b333ec5f329ebeaaa"
}
}
Request:
curl --include --request PATCH http://localhost:3000/change-password/$ID \
--header "Authorization: Token token=$TOKEN" \
--header "Content-Type: application/json" \
--data '{
"passwords": {
"old": "an example password",
"new": "super sekrit"
}
}'
ID=1 TOKEN=33ad6372f795694b333ec5f329ebeaaa scripts/change-password.sh
Response:
HTTP/1.1 204 No Content
Request:
curl --include --request DELETE http://localhost:3000/sign-out/$ID \
--header "Authorization: Token token=$TOKEN"
ID=1 TOKEN=33ad6372f795694b333ec5f329ebeaaa scripts/sign-out.sh
Response:
HTTP/1.1 204 No Content
Verb | URI Pattern | Controller#Action |
---|---|---|
GET | /users |
users#index |
GET | /users/1 |
users#show |
Request:
curl --include --request GET http://localhost:3000/users \
--header "Authorization: Token token=$TOKEN"
TOKEN=33ad6372f795694b333ec5f329ebeaaa scripts/users.sh
Response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"users": [
{
"id": 2,
"email": "another@example.email"
},
{
"id": 1,
"email": "an@example.email"
}
]
}
Request:
curl --include --request GET http://localhost:3000/users/$ID \
--header "Authorization: Token token=$TOKEN"
ID=2 TOKEN=33ad6372f795694b333ec5f329ebeaaa scripts/user.sh
Response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"user": {
"id": 2,
"email": "another@example.email"
}
}
Source code distributed under the MIT license. Text and other assets copyright General Assembly, Inc., all rights reserved.