An API for ember-resources
- [Fork and] clone this repository.
- Install dependencies with
bundle install
. - Create a
.env
for sensitive settings (touch .env
). - Generate new
development
andtest
secrets (bundle exec rake secret
). - Store them in
.env
with keysSECRET_KEY_BASE_<DEVELOPMENT|TEST>
respectively. - 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!
bin/rake routes
lists the endpoints available in your API.bin/rake test
runs automated tests.bin/rails console
opens a REPL that pre-loads the API.bin/rails db
opens your database client and loads the correct database.bin/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:4741/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:4741/lists/$ID
Response:
{
"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 Content
Request:
curl --include --request DELETE http://localhost:4741/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: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/$ID
Response:
{
"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 Content
Request:
curl --include --request DELETE http://localhost:4741/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 http://localhost:4741/sign-up \
--include \
--request POST \
--header "Content-Type: application/json" \
--data '{
"credentials": {
"email": "'"${EMAIL}"'",
"password": "'"${PASSWORD}"'",
"password_confirmation": "'"${PASSWORD}"'"
}
}'
EMAIL=ava@bob.com PASSWORD=hannah scripts/sign-up.sh
Response:
HTTP/1.1 201 Created
Content-Type: application/json; charset=utf-8
{
"user": {
"id": 1,
"email": "ava@bob.com"
}
}
Request:
curl http://localhost:4741/sign-in \
--include \
--request POST \
--header "Content-Type: application/json" \
--data '{
"credentials": {
"email": "'"${EMAIL}"'",
"password": "'"${PASSWORD}"'"
}
}'
EMAIL=ava@bob.com PASSWORD=hannah scripts/sign-in.sh
Response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"user": {
"id": 1,
"email": "ava@bob.com",
"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.sh
Response:
HTTP/1.1 204 No Content
Request:
curl http://localhost:4741/sign-out/$ID \
--include \
--request DELETE \
--header "Authorization: Token token=$TOKEN"
ID=1 TOKEN=BAhJIiVlZDIwZTMzMzQzODg5NTBmYjZlNjRlZDZlNzYxYzU2ZAY6BkVG--7e7f77f974edcf5e4887b56918f34cd9fe293b9f 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 http://localhost:4741/users \
--include \
--request GET \
--header "Authorization: Token token=$TOKEN"
TOKEN=BAhJIiVlZDIwZTMzMzQzODg5NTBmYjZlNjRlZDZlNzYxYzU2ZAY6BkVG--7e7f77f974edcf5e4887b56918f34cd9fe293b9f scripts/users.sh
Response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"users": [
{
"id": 2,
"email": "bob@ava.com"
},
{
"id": 1,
"email": "ava@bob.com"
}
]
}
Request:
curl --include --request GET http://localhost:4741/users/$ID \
--header "Authorization: Token token=$TOKEN"
ID=2 TOKEN=BAhJIiVlZDIwZTMzMzQzODg5NTBmYjZlNjRlZDZlNzYxYzU2ZAY6BkVG--7e7f77f974edcf5e4887b56918f34cd9fe293b9f scripts/user.sh
Response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"user": {
"id": 2,
"email": "bob@ava.com"
}
}
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 legal@ga.co.