This REST API is a partial design of a back end for a tea subscription service. It offers clients the ability to send request to get all subscriptions for a customer, create a new customer subscription, or deactivate a customer subscription.
Rails 5.2.8.1
Ruby 2.7.4
RSpec 3.1.2
PostgreSQL
- Fork and clone this repository
cd
into the root directory- Run
bundle install
- Run
rails db:{drop,create,migrate}
to setup the databases - Run
bundle exec rspec
to run the test suite - Run
rails server
to start the rails server athttp://localhost:3000
- Example of requests you can send are available below
Request
get '/api/v1/subscriptions'
Body
{ "customer_id" = "1" }
Response
{
"data": [
{
"id": "1",
"type": "subscription",
"attributes": {
"title": "Hibiscus",
"price": 6.81,
"active": false,
"frequency": "quarterly",
"customer_id": 1,
"tea_id": 9,
"created_at": "2023-04-13T00:49:06.976Z",
"updated_at": "2023-04-13T00:49:06.976Z"
}
},
{
"id": "10",
"type": "subscription",
"attributes": {
"title": "Che Dang",
"price": 58.74,
"active": true,
"frequency": "monthly",
"customer_id": 1,
"tea_id": 3,
"created_at": "2023-04-13T00:49:07.019Z",
"updated_at": "2023-04-13T00:49:07.019Z"
}
},
{
"id": "19",
"type": "subscription",
"attributes": {
"title": "Shui Xian",
"price": 17.71,
"active": true,
"frequency": "quarterly",
"customer_id": 1,
"tea_id": 10,
"created_at": "2023-04-13T00:49:07.055Z",
"updated_at": "2023-04-13T00:49:07.055Z"
}
}
]
}
Request
post '/api/v1/subscriptions'
Body
{
"title": 'Test Tea Subscription',
"price": 5.99,
"frequency": 1,
"customer_id": 5,
"tea_id": 10
}
Response
{
"success": "Subscription added successfully"
}
Request
patch '/api/v1/subscriptions/<subscription_id>'
Body
{ "customer_id" : "1" }
Response
{
"data": {
"id": "4",
"type": "subscription",
"attributes": {
"title": "Darjeeling",
"price": 20.65,
"active": false,
"frequency": "quarterly",
"customer_id": 1,
"tea_id": 6,
"created_at": "2023-04-13T19:21:00.526Z",
"updated_at": "2023-04-13T21:07:12.001Z"
}
}
}