Giter VIP home page Giter VIP logo

smoothies's Introduction

Smoothies

Next.js-based API for managing recipes


Live demo available here.

Getting started

Clone the repository:

$ git clone [email protected]:tylucaskelley/smoothies

System-level dependencies

Install the following:

Local setup

Run yarn install to grab project dependencies. Next, configure a MySQL 8.0 database for use during local development. Copy .env.example to .env and fill in the database configuration information.

Then, run database migrations:

$ yarn migrate

Once done, start the local development server:

$ yarn dev

Testing endpoints

The following examples use the HTTPie client:

POST /api/recipes

Creates a new recipe, can optionally include ingredients as well:

$ http post http://localhost:3000/api/recipes \
    title="Strawberry Smoothie" author="Ty Kelley" description="A strawberry smoothie" prepTime=15 cookingTime=5 servings=4 \
    ingredients:='[{ "name": "Sugar", "quantity": 5, "unit": "tsp" }, {"name": "Strawberries", "quantity": 2, "unit": "cups"}]' \
    --verbose

Request body example:

{
  "author": "Ty Kelley",
  "description": "A strawberry smoothie",
  "ingredients": [
    {
      "name": "Sugar",
      "quantity": 5,
      "unit": "tsp"
    },
    {
      "name": "Strawberries",
      "quantity": 2,
      "unit": "cups"
    }
  ],
  "title": "Strawberry Smoothie",
  "prepTime": 15,
  "cookingTime": 5,
  "servings": 4
}

The title of a recipe must be unique within the system.

GET /api/recipes

Retrieve a list of recipes:

$ http get http://localhost:3000/api/recipes --verbose

GET /api/recipes/:id

Retrieve a single recipe, by ID:

$ http get http://localhost:3000/api/recipes/1 --verbose

PATCH /api/recipes/:id

Update a recipe and its ingredients. Only provide the fields you want to update:

$ http patch http://localhost:3000/api/recipes/1 title="Even better strawberry smoothie" --verbose

In the request body example below, note that new ingredients as well as existing ingredients can be handled.

  1. Passing in the ID of an existing ingredient will update it with the other changes
  2. Creating a new object (no ID) will add a new ingredient
  3. If the ingredients array is provided, any existing ingredients that are omitted will be deleted automatically.
{
  "ingredients": [
    {
      "name": "Sugar",
      "id": 14,
      "quantity": 3,
      "unit": "tsp"
    },
    {
      "name": "Oranges",
      "quantity": 2,
      "unit": "slices"
    }
  ],
  "title": "Strawberry Smoothie w/ Orange"
}

DELETE /api/recipes/:id

Delete a recipe, by ID:

$ http delete http://localhost:3000/api/recipes/1 --verbose

Testing

Code style

Code is formatted automatically with Prettier, via a pre-commit hook. A few tasks are available as well:

  • yarn lint: Check code style with ESLint, configured with TypeScript support
  • yarn format: Format code using Prettier
  • yarn type-check: Validate TypeScript type annotations and catch errors

Automated tests

Run yarn test to test the API endpoints; note that a working database connection is needed for tests to function.

License

See LICENSE file for details.

smoothies's People

Stargazers

Vince Fulco--Bighire.tools avatar

Watchers

James Cloos avatar Lara Kelley avatar  avatar

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.