Skip to content

robin-hodge/robots-api

Repository files navigation

Robot Stores API

Use the json file in this repo to set up the database.

API documentation

Return all products - optionally filtered

  • URL

    /products

  • Method:

    GET

  • Query Params

    Required:

    There are no required URL params

    Optional:

    categories=[string] - A comma seperated list of category strings
    characters=[string] - A comma seperated list of character strings

    Example:

    /products?categories=Aprons,Mugs&characters=Bubbles,Rex

  • Success Response:

    • Code: 200
      Content:
    {
    "message": "Successfully found products.",
    "data": [
      {
        "id": "63a06c1f39e63776d2b2809f",
        "title": "It's All 0's and 1's to Me! Apron",
        "price": 24,
        "image": "https://binaryville.com/images/products/fred-0s1s-apron-black.jpg",
        "category": "Aprons",
        "character": "Fred"
      },
      {
        "id": "63a06c1f39e63776d2b280a0",
        "title": "I Compute, Therefore I Am Apron",
        "price": 24,
        "image": "https://binaryville.com/images/products/dolores-compute-apron-black.jpg",
        "category": "Aprons",
        "character": "Dolores"
      }
    ]
    }
  • Error Response:

    • Code: 400 BAD REQUEST
      Content: {"message": "Unknown category", "data": []}

    • Code: 400 BAD REQUEST
      Content: {"message": "Unknown character", "data": []}

    • Code: 500 SERVER ERROR
      Content: {"message": "Unexpected error", "data": []}

Return specific product

  • URL

    /products/{id}

  • Method:

    GET

  • URL Params

    Required:

    There are no required URL params

    Optional:

    There are no optional URL params

    Example:

    /products/63a06c1f39e63776d2b280a0

  • Success Response:

    • Code: 200
      Content:
    {
    "message": "Successfully found product.",
    "data": 
      {
        "id": "63a06c1f39e63776d2b2809f",
        "title": "I Compute, Therefore I Am Baseball Hat",
        "price": 29,
        "image": "https://binaryville.com/images/products/dolores-compute-baseballhat-black.jpg",
        "category": "Baseball Hats",
        "character": "Dolores",
        "description": "Cheer the team on in style with our unstructured, low crown, six-panel baseball cap made of 100% organic cotton twill. Featuring our original Binaryville artwork, screen-printed with PVC- and phthalate-free inks. Complete with matching, sewn eyelets, and adjustable fabric closure. ",
        "image2": "https://binaryville.com/images/products/dolores-compute-baseballhat-gray.jpg",
        "image3": "NULL"
      }
    }
  • Error Response:

    • Code: 400 BAD REQUEST
      Content: {"message": "Unknown product ID", "data": []}

    • Code: 500 SERVER ERROR
      Content: {"message": "Unexpected error", "data": []}

Add new product - STRETCH GOAL

  • URL

    /products

  • Method:

    POST

  • URL Params

    Required:

    There are no required URL params

    Optional:

    There are no optional URL params

  • Body Data

    Must be sent as JSON with the correct headers

    Required:

    {
      "title": "String",
      "price": Number,
      "image": "URL string",
      "category": "String",
      "character": "String",
      "description": "String"
    }

    Optional:

    {
      "image2": "URL string"|null,
      "image3": "URL string"|null
    }

    Example:

    /products

  • Success Response:

    • Code: 201 CREATED
      Content:
    {"message": "Successfully created product.",
    "data": []
    }
  • Error Response:

    • Code: 400 BAD REQUEST
      Content: {"message": "Invalid product data", "data": []}

    • Code: 500 SERVER ERROR
      Content: {"message": "Unexpected error", "data": []}

About

A RESTful API built using Express and Node

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published