Code Monkey home page Code Monkey logo

rails-api's Introduction

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

rails-api's People

Contributors

philmccarthy avatar

Watchers

James Cloos avatar  avatar

Forkers

b-enji-cmd

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.