An API for ember-resources
- [Fork and] clone this repository.
- Install dependencies with
bundle install. - Create a
.envfor sensitive settings (touch .env). - Generate new
developmentandtestsecrets (bundle exec rake secret). - Store them in
.envwith keysSECRET_KEY_BASE_<DEVELOPMENT|TEST>respectively. - Setup your database with
bin/rake db:nuke_paveorbundle exec rake db:nuke_pave. - Run the API server with
bin/rails serverorbundle exec rails server.
Developers should run these often!
bin/rake routeslists the endpoints available in your API.bin/rake testruns automated tests.bin/rails consoleopens a REPL that pre-loads the API.bin/rails dbopens your database client and loads the correct database.bin/rails serverstarts the API.scripts/*.shrun variouscurlcommands 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:4741/listsResponse:
[
{
"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:4741/lists/$IDResponse:
{
"id": 1,
"title": "Favorite Things",
"hidden": false,
"items": [
1,
2,
3,
4,
5
]
}Request:
curl --include --request POST http://localhost:4741/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:4741/lists/$ID \
--header "Content-Type: application/json" \
--data '{
"list": {
"hidden": true
}
}'Response:
HTTP/1.1 204 No ContentRequest:
curl --include --request DELETE http://localhost:4741/lists/$IDResponse:
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:4741/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:4741/items/$IDResponse:
{
"id": 1,
"content": "Cats",
"done": false,
"list": 1
}Request:
curl --include --request POST http://localhost:4741/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:4741/items/$ID \
--header "Content-Type: application/json" \
--data '{
"item": {
"done": true,
}
}'Response:
HTTP/1.1 204 No ContentRequest:
curl --include --request DELETE http://localhost:4741/items/$IDResponse:
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 http://localhost:4741/sign-up \
--include \
--request POST \
--header "Content-Type: application/json" \
--data '{
"credentials": {
"email": "'"${EMAIL}"'",
"password": "'"${PASSWORD}"'",
"password_confirmation": "'"${PASSWORD}"'"
}
}'[email protected] PASSWORD=hannah scripts/sign-up.shResponse:
HTTP/1.1 201 Created
Content-Type: application/json; charset=utf-8
{
"user": {
"id": 1,
"email": "[email protected]"
}
}Request:
curl http://localhost:4741/sign-in \
--include \
--request POST \
--header "Content-Type: application/json" \
--data '{
"credentials": {
"email": "'"${EMAIL}"'",
"password": "'"${PASSWORD}"'"
}
}'[email protected] PASSWORD=hannah scripts/sign-in.shResponse:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"user": {
"id": 1,
"email": "[email protected]",
"token": "BAhJIiVlZDIwZTMzMzQzODg5NTBmYjZlNjRlZDZlNzYxYzU2ZAY6BkVG--7e7f77f974edcf5e4887b56918f34cd9fe293b9f"
}
}Request:
curl --include --request PATCH "http://localhost:4741/change-password/$ID" \
--header "Authorization: Token token=$TOKEN" \
--header "Content-Type: application/json" \
--data '{
"passwords": {
"old": "'"${OLDPW}"'",
"new": "'"${NEWPW}"'"
}
}'ID=1 OLDPW=hannah NEWPW=elle TOKEN=BAhJIiVlZDIwZTMzMzQzODg5NTBmYjZlNjRlZDZlNzYxYzU2ZAY6BkVG--7e7f77f974edcf5e4887b56918f34cd9fe293b9f scripts/change-password.shResponse:
HTTP/1.1 204 No ContentRequest:
curl http://localhost:4741/sign-out/$ID \
--include \
--request DELETE \
--header "Authorization: Token token=$TOKEN"ID=1 TOKEN=BAhJIiVlZDIwZTMzMzQzODg5NTBmYjZlNjRlZDZlNzYxYzU2ZAY6BkVG--7e7f77f974edcf5e4887b56918f34cd9fe293b9f scripts/sign-out.shResponse:
HTTP/1.1 204 No Content| Verb | URI Pattern | Controller#Action |
|---|---|---|
| GET | /users |
users#index |
| GET | /users/1 |
users#show |
Request:
curl http://localhost:4741/users \
--include \
--request GET \
--header "Authorization: Token token=$TOKEN"TOKEN=BAhJIiVlZDIwZTMzMzQzODg5NTBmYjZlNjRlZDZlNzYxYzU2ZAY6BkVG--7e7f77f974edcf5e4887b56918f34cd9fe293b9f scripts/users.shResponse:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"users": [
{
"id": 2,
"email": "[email protected]"
},
{
"id": 1,
"email": "[email protected]"
}
]
}Request:
curl --include --request GET http://localhost:4741/users/$ID \
--header "Authorization: Token token=$TOKEN"ID=2 TOKEN=BAhJIiVlZDIwZTMzMzQzODg5NTBmYjZlNjRlZDZlNzYxYzU2ZAY6BkVG--7e7f77f974edcf5e4887b56918f34cd9fe293b9f scripts/user.shResponse:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"user": {
"id": 2,
"email": "[email protected]"
}
}This is not a task developers should run often, but it is sometimes necessary.
- locally
bin/rake db:migrate VERSION=0
bin/rake db:migrate db:seed db:examples- heroku
heroku run rake db:migrate VERSION=0
heroku run rake db:migrate db:seed db:examples- All content is licensed under a CCBYNCSA 4.0 license.
- All software code is licensed under GNU GPLv3. For commercial use or alternative licensing, please contact [email protected].