Table of Contents
This Rails-backed JSON API was built in 6 days while I was in Mod 3 of Turing School's Backend Engineering program.
Areas of exploration and learning on this project included:
- Expose an API
- Use serializers to format JSON responses
- Test API exposure with RSpec and Postman
- Compose advanced ActiveRecord queries to analyze information stored in PostgreSQL database
- Write SQL statements without the assistance of an ORM
- Implement json:api standards
- Add custom error responses for invalid API requests
-
Clone this repo
-
Install gem packages:
bundle
-
Setup the database. A pgdump is included in
./db
to seed the databaserails db:{create,migrate,seed}
-
Run the RSpec test suite:
bundle exec rspec
-
Start your local server:
rails s
A Postman test suite also exists to test the endpoints served via localhost!
- Download the Postman Collection JSON file (right click the link and 'save as')
- In Postman, in the top left corner, click on the 'Import' button, and drag the downloaded JSON file over the interface or use the file selector to locate the file on your operating system. Click 'Import' to continue
- In the top left corner of the Postman interface, you’ll see a 'Runner' button. Click that and a new Postman window will appear. From here, you can select 'Rails API (by Phil McCarthy)' from the list of 'All Collections'
- Ruby 2.5.3
- Rails 5.2.4
Optional Parameters: ?per_page
(defaults to 20 results) and ?page
.
GET /api/v1/merchants?per_page=x&page=x
GET /api/v1/merchants/:id
GET /api/v1/merchants/:id/items
Optional Parameters: ?per_page
(defaults to 20 results) and ?page
.
GET /api/v1/items?per_page=x&page=x
GET /api/v1/items/:id
GET /api/v1/items/:id/merchant
PATCH /api/v1/items/:id
Item attributes:
{
"name": "value1",
"description": "value2",
"unit_price": 100.99,
"merchant_id": 14
}
POST /api/v1/items/
Create item body format:
{
"name": "value1",
"description": "value2",
"unit_price": 100.99,
"merchant_id": 14
}
DELETE /api/v1/items/:id
Required Parameter: ?name
.
GET /api/v1/merchants/find_all?name=x
Parameter(s): ?name
, min_price
and max_price
.
- At least one parameter is required
- Name cannot be combined with either/both price parameters
- Minimum price and maximum price can be used alone or together to query a price range
GET /api/v1/items/find?name=x OR ?min_price=x&max_price=y
Required Parameter: ?quantity
is required
GET /api/v1/revenue/merchants?quantity=x
Optional Parameter: ?quantity
is not required for this query. Defaults to 5 results.
GET /api/v1/merchants/most_items?quantity=
GET /api/v1/revenue/merchants/:id
Optional Parameter: ?quantity
is not required. Defaults to 10 results.
GET /api/v1/revenue/items?quantity=x
Optional Parameter: ?quantity
is not required. Defaults to 10 results.
GET /api/v1/revenue/unshipped?quantity=x
Phil McCarthy — LinkedIn — philmccarthy.dev