Skip to content

philmccarthy/rails-api

Repository files navigation

LinkedIn

Table of Contents
  1. About The Project
  2. Getting Started
  3. ReST Endpoints
  4. Non-ReST Endpoints
  5. Contact

About The Project

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

Built With

Getting Started

  1. Clone this repo

  2. Install gem packages: bundle

  3. Setup the database. A pgdump is included in ./db to seed the database

    rails db:{create,migrate,seed}

  4. Run the RSpec test suite: bundle exec rspec

  5. 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'

Prerequisites

  • Ruby 2.5.3
  • Rails 5.2.4

ReST Endpoints

Get All Merchants

Optional Parameters: ?per_page (defaults to 20 results) and ?page.

GET /api/v1/merchants?per_page=x&page=x

Get One Merchant

GET /api/v1/merchants/:id

Get a Merchant's Items

GET /api/v1/merchants/:id/items

Get All Items

Optional Parameters: ?per_page (defaults to 20 results) and ?page.

GET /api/v1/items?per_page=x&page=x

Get One Item

GET /api/v1/items/:id

Get an Item's Merchant

GET /api/v1/items/:id/merchant

Update One Item

PATCH /api/v1/items/:id

Item attributes:

{
  "name": "value1",
  "description": "value2",
  "unit_price": 100.99,
  "merchant_id": 14
}

Create One Item

POST /api/v1/items/

Create item body format:

{
  "name": "value1",
  "description": "value2",
  "unit_price": 100.99,
  "merchant_id": 14
}

Delete One Item

DELETE /api/v1/items/:id

Non-ReST Endpoints

Find All Merchants by Fragment

Required Parameter: ?name.

GET /api/v1/merchants/find_all?name=x

Find One Item by Fragment

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

Get Merchants with Most Revenue

Required Parameter: ?quantity is required

GET /api/v1/revenue/merchants?quantity=x

Get Merchants who Sold Most Items

Optional Parameter: ?quantity is not required for this query. Defaults to 5 results.

GET /api/v1/merchants/most_items?quantity=

Get Revenue of a Single Merchant

GET /api/v1/revenue/merchants/:id

Get Items with Most Revenue

Optional Parameter: ?quantity is not required. Defaults to 10 results.

GET /api/v1/revenue/items?quantity=x

Get Potential Revenue of Unshipped Invoices

Optional Parameter: ?quantity is not required. Defaults to 10 results.

GET /api/v1/revenue/unshipped?quantity=x

Contact

Phil McCarthy — LinkedInphilmccarthy.dev

About

A JSON API that serves up REST and business intelligence endpoints.

Topics

Resources

Stars

Watchers

Forks