Phumblr API
https://cpstrillvt93.github.io/phumblr/
https://lit-beyond-80860.herokuapp.com/
https://github.com/cpstrillvt93/phumblr
https://github.com/cpstrillvt93/phumblr-api
http://i.imgur.com/ecllvpO.jpg
http://i.imgur.com/nI2fd9v.jpg
http://i.imgur.com/zQT4gXY.jpg
Install with bundle install.
Until Rails 5 is released, this template should follow the most recent released
version of Rails 4, as well as track master branches for rails-api and
active_model_serializers.
- Download this template.
- Unzip and rename the template directory.
- Empty
README.mdand fill with your own content. - Move into the new project and
git init. - Install dependencies with
bundle install. - Rename your app module in
config/application.rb(changeRailsApiTemplate). - Rename your project database in
config/database.yml(change'rails-api-template'). - Create a
.envfor sensitive settings (touch .env). - Generate new
developmentandtestsecrets (bundle exec rake secret). - Store them in
.envwith keysSECRET_KEY_BASE_<DEVELOPMENT|TEST>respectively. - In order to make requests to your deployed API, you will need to set
SECRET_KEY_BASEin the environment of the production API (usingheroku config:setor the Heroku dashboard). - In order to make requests from your deployed client application, you will
need to set
CLIENT_ORIGINin the environment of the production API (e.g.heroku config:set CLIENT_ORIGIN https://<github-username>.github.io). - 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.
This template follows the standard project structure in Rails 4.
curl command scripts are stored in scripts with names that
correspond to API actions.
User authentication is built-in.
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.
I started the project by focusing on my user storires, my ERD, and scoping my project down to something that I was confident I could accomplish in the alotted time. To start off on the right foot, I deployed both my heroku back-end and the ember auth template. With slightly more experience using Rails than ember, I decided it would be best to get my rails server up and running first. Though it took longer than the last time I used rails, I was able to get all my curl scripts running within a day and a half. I then moved on to my first ember experience.
Similar to how I approached using the browser-template, I first broke ember down into a diagram so that I could at least go into building my application with something to go off of. My first goal was to get phumblr crudding. Unlike using the browser template however, this was much easier with ember, as it seemed to seemelessly pull the data from my server. The 'magic' aspect of Ember certainly caused quite a few mishaps and frustrating bugs, however I am happy I decided to give it a try.
Getting around the ember stuff that I did(and may still) not understand was probably made up the majority of the largest hurdles I made. When I had code that to me looked perfect, or at least should have worked, I spent hours combing through it, only to find that it was one parameter being required in my back-end, or a '/' precedeing my 'page-not-found' route. While I am proud of my ability to learn a front-end framework like Ember, I definitely felt a bit discouraged at certain times throughout the framework-learning proccess. I plan to continue working on this app after GA ends.
Use this as the basis for your own API documentation. Add a new third-level heading for your custom entities, and follow the pattern provided for the built-in user authentication documentation.
Scripts are included in scripts to test built-in actions. Add your
own scripts to test your custom API. As an alternative, you can write automated
tests in RSpec to test your API.
| 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.shResponse:
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.shResponse:
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.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": "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.shResponse:
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
{
"user": {
"id": 2,
"email": "bob@ava.com"
}
}Verb URI Pattern Controller#Action POST /posts posts#create GET /posts posts#index GET /posts/:id posts#show PATCH /posts/:id posts#update DELETE /posts/:id posts#destroy
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:examplesheroku
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.