Time-4-T is a backend database application that contains linked customers, teas, and tea subscriptions. It follows guidelines on this site to create 4 RESTful endpoints:
- POST /api/v0/customers/new
- POST /api/v0/customers/:id/subscription/:id
- PUT /api/v0/customers/:id/subscription/:id
- GET /api/v0/customers/:id/subscriptions
- Fork and clone this repository
- from the command line, run
bundle install
andrails db:{drop,create,migrate,seed}
- run
bundle exec rspec
. You should see 18 passing tests. - run
rails s
. The backend application will now be running onlocalhost:3000
Time-4-T uses serializers to return JSON in response to requests to the 4 endpoints listed above. Sample requests and parsed responses are provided below.
No authorization is required for requests to this API.
Requests to create a new customer must include the customer data in the request body, including first name, last name, email, and address.
A successful response will contain the customer's ID and the attributes passed in the request.
Requests to create a new user subscription must include the customer id and the subscription id in the body. Optionally, the subscription status can be passed as an enum ({ active: 0, paused: 1, cancelled: 2}). The default status is active.
A successful response will have a status code 201 and contain the customer subscription attributes, including the customer id, the subscription id, and the customer subscription status as a string.
The response body will be in JSON format. A parsed example of a successful response body is shown below.
{:data=>
{:id=>"122",
:type=>"customer_subscription",
:attributes=>{:customer_id=>116, :subscription_id=>136, :status=>"active"}}}
Requests to change a customer subscription status should be sent to this endpoint, and optionally contain the desired updated status as an enum integer ({ active: 0, paused: 1, cancelled: 2}). Without an argument, the status will default to active.
A successful response will have a status code 200 and contain the customer subscription attributes, including the customer id, the subscription id, and the customer subscription status as a string.
The response body will be in JSON format. A parsed example of a successful response body is shown below.
{:data=>
{:id=>"128",
:type=>"customer_subscription",
:attributes=>{:customer_id=>122, :subscription_id=>143, :status=>"cancelled"}}}
Requests to GET
all customer subscriptions should be sent to this endpoint. A request body is not necessary.
A successful response will have a status code 200 and contain a collection of the customer's customer subscription attributes, including the customer id, the subscription id, and the customer subscription status as a string.
The response body will be in JSON format. A parsed example of a successful response body is shown below.
{:data=>
[{:id=>"113",
:type=>"customer_subscription",
:attributes=>{:customer_id=>113, :subscription_id=>127, :status=>"active"}},
{:id=>"114",
:type=>"customer_subscription",
:attributes=>{:customer_id=>113, :subscription_id=>128, :status=>"active"}},
{:id=>"115",
:type=>"customer_subscription",
:attributes=>{:customer_id=>113, :subscription_id=>129, :status=>"active"}}]}