A RESTful Rails API for a Tea Subscription Service.
Built Using | Database Schema | Setup | Endpoints | Testing | Making a Contribution | Developer
- Ruby (version 2.5.3p105)
- Ruby on Rails (version 5.2.6)
- PostgreSQL (version 13)
This project was tested with:
- RSpec version 3.10
- Postman Explore and test the API endpoints
- [pry] https://github.com/pry/pry
- Fork and clone this repository
- change directories into
tea-api
and run the commandbundle install
in your terminal - To set up the database and seed it, run
rails db:{create,mirgrate,seed}
orrails db:setup
- Start your server with the
rails s
command - Now you're ready to consume the endpoints below
All endpoints run off base URL http://localhost:3000 on a local machine.
Method | URI | Description |
---|---|---|
POST |
/api/v1/customers/:customer_id/subscriptions |
Add a subscription record |
Example Request: Needs following information in the request body
body:
{
"tea_id": 1,
"title": "Subscription for delicious tea",
"price": 12.05,
"status": "active",
"frequency": 1
}
Example Response:
{
"data": {
"id": "9",
"type": "subscription",
"attributes": {
"id": 9,
"customer_id": 1,
"tea_id": 5,
"title": "Subscription for delicious tea",
"price": 12.05,
"status": "active",
"frequency": 1
}
}
}
Method | URI | Description |
---|---|---|
PATCH |
/api/v1/customers/:customer_id/subscriptions/:id |
Updates the customer's subscription status to inactive |
Example Request:
The URI includes the customer id and the subscription id so this request requires the status to be sent in the params.
Status can be sent "inactive". Inversely, to activate an inactive subscription the status could be sent as "active".
URL: http://localhost:3000/api/v1/customers/1/subscriptions/3
Params: status: "inactive
Example Response:
{
"data": {
"id": "3",
"type": "subscription",
"attributes": {
"id": 3,
"customer_id": 1,
"tea_id": 3,
"title": "Ut praesentium magni.",
"price": 12.44,
"status": "inactive",
"frequency": 1
}
}
}
Method | URI | Description |
---|---|---|
GET |
/api/v1/customers/:customer_id/subscriptions |
Retrives all subscriptions for customer |
Example Request:
URL: http://localhost:3000/api/v1/customers/1/subscriptions
Example Response:
{
"data": [
{
"id": "3",
"type": "subscription",
"attributes": {
"id": 3,
"customer_id": 1,
"tea_id": 3,
"title": "Ut praesentium magni.",
"price": 12.44,
"status": "inactive",
"frequency": 1
}
},
{
"id": "6",
"type": "subscription",
"attributes": {
"id": 6,
"customer_id": 1,
"tea_id": 1,
"title": "Subscription for delicious tea",
"price": 12.05,
"status": "active",
"frequency": 1
}
}
]
}
- Tested with Rspec
- Model and request tests
- 100% coverage
- To run tests, use the command
bundle exec rspec
- Te see coverage, use the command
open coverage/index.html
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request