A backedn API for storing and implement trips planing data. Includes authentication.
FRONTEND REPO: https://github.com/newayliu1/plan-a-trip-browser
bundle install
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#Actio |
|---|---|---|
| GET | /trips |
trips#index |
| GET | /trips/:id |
trips#show |
| POST | /trips/ |
trips#create |
| PATCH | /trips |
trips#update |
| DELETE | /trips |
tripss#delete |
| Verb | URI Pattern | Controller#Action |
|---|---|---|
| GET | /attractions |
attractions#index |
| GET | /attractions/:id |
attractions#show |
| POST | /attractions/ |
attractions#create |
| PATCH | /attractions |
attractions#update |
| DELETE | /attractions |
attractionss#delete |
| 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"
}
}The database struction of this project is not complicate. The database struction like a tree diagram, one user has many trips, and one trip has many attractions. Once the ERD was decided, building out the api did not take me much time.
The next step of this project is implement google map direction API, so that the front end is able to look up the travel time between two attractions.
- ruby
- Ruby on Rails
- PostgreSQL