GithubHelp home page GithubHelp logo

hypermedia-api-server's Introduction

React Server

This app contains all of the endpoints needed for the entire React Curriculum.

For example:

NOTE

This server stores everything in-memory, so every time you restart the server, you get a clean slate.

Install

yarn
yarn start

Then you can see the API running on http://localhost:8181

API Endpoints

This API uses Hypermedia. So once you make the first request to the index path, you can get all the URLs from that point on.

GET /api

{
  "_links": {
    "self": {
      "href": "http://localhost:8181/"
    },
    "messages": {
      "href": "http://localhost:8181/api/messages"
    },
    "people": {
      "href": "http://localhost:8181/api/people"
    }
  }
}

Messages

GET /api/messages

Response:

{
  "_links": {
    "self": {
      "href": "http://localhost:8181/api/messages"
    }
  },
  "_embedded": {
    "messages": [
      {
        "_links": {
          "self": {
            "href": "http://localhost:8181/api/messages/1"
          }
        },
        "id": 1,
        "subject": "Hi",
        "starred": true,
        "read": true,
        "labels": [
          "dev",
          "personal"
        ]
      },
      {
        "_links": {
          "self": {
            "href": "http://localhost:8181/api/messages/2"
          }
        },
        "id": 2,
        "subject": "Hi again",
        "starred": false,
        "read": false,
        "labels": []
      }
    ],
  }
}

GET /api/messages/:id

Response (notice that there is a body field in this response that is not present in the /api/messages endpoint):

{
  "_links": {
    "self": {
      "href": "http://localhost:8181/api/messages/1"
    }
  },
  "id": 1,
  "subject": "Hi",
  "starred": true,
  "read": true,
  "labels": [
    "dev",
    "personal"
  ],
  "body": "Hello there"
}

POST /api/messages

Request:

{
  "subject": "I created this",
  "body": "And it is sent"
}

Response:

{
  "_links": {
    "self": {
      "href": "http://localhost:8181/api/messages/1"
    }
  },
  "id": 1,
  "subject": "I created this",
  "starred": false,
  "read": false,
  "labels": [],
  "body": "And it is sent"
}

PATCH /api/messages

The request body can be any of these:

{
  "messageIds": [ 1, 3 ],
  "command": "star",
  "star": false
}

star can be true or false.

{
  "messageIds": [ 1, 3 ],
  "command": "read",
  "read": true
}

read can be true or false.

{
  "messageIds": [ 1, 3 ],
  "command": "delete"
}
{
  "messageIds": [ 1, 3 ],
  "command": "addLabel",
  "label": "dev"
}
{
  "messageIds": [ 1, 3 ],
  "command": "removeLabel",
  "label": "dev"
}

Response: An HTTP 200 Response

Products

GET /api/products

{
  "_links": {
    "self": {
      "href": "http://localhost:8181/api/products"
    }
  },
  "_embedded": {
    "products": [
      {
        "_links": {
          "self": {
              "href": "http://localhost:8181/api/products/1"
          },
          "items": {
            "href": "http://localhost:8181/api/products/1/items"
          }
        },
        "id": 1,
        "name": "Mediocre Iron Watch",
        "priceInCents": 399
      }
    ]
  }
}

GET /api/products/:id

{
  "_links": {
    "self": {
      "href": "http://localhost:8181/api/products/1"
    },
    "items": {
      "href": "http://localhost:8181/api/products/1/items"
    }
  },
  "id": 1,
  "name": "Mediocre Iron Watch",
  "priceInCents": 399
}

Shopping Cart Items

GET /api/items

note that the products returned by this call are only the ones that are referenced by one or more of the items. For a list of all products use the api/products endpoint.

{
  "_links": {
    "self": {
      "href": "http://localhost:8181/api/items"
    }
  },
  "_embedded": {
    "items": [
      {
        "id": 1,
        "quantity": 1,
        "product": {
          "ref": "http://localhost:8181/api/products/1",
          "id": 1
        }
      }
    ],
    "products": [
      {
        "_links": {
          "self": {
            "href": "http://localhost:8181/api/products/1"
          },
          "items": {
            "href": "http://localhost:8181/api/products/1/items"
          }
        },
        "id": 1,
        "name": "Mediocre Iron Watch",
        "priceInCents": 399
      }
    ]
  }
}

POST /api/products/:productId/items

Request body:

{ "quantity": 45 }

Response body:

{
  "id": 1,
  "quantity": 1,
  "product": {
    "ref": "http://localhost:8181/api/products/1",
    "id": 1
  }
}

People

GET /api/people

Response:

{
  "_links": {
    "self": {
      "href": "http://localhost:8181/api/people"
    }
  },
  "_embedded": {
    "people": [
      {
        "_links": {
          "self": {
            "href": "http://localhost:8181/api/people/1"
          },
          "meetings": {
            "href": "http://localhost:8181/api/people/1/meetings"
          }
        },
        "id": 1,
        "name": "Frida Kuvalis"
      },
      {
        "_links": {
          "self": {
            "href": "http://localhost:8181/api/people/2"
          },
          "meetings": {
            "href": "http://localhost:8181/api/people/2/meetings"
          }
        },
        "id": 2,
        "name": "Demarcus Mayer"
      }
    ]
  }
}

GET /api/people/:id

Response:

{
  "_links": {
    "self": {
      "href": "http://localhost:8181/api/people/1"
    },
    "meetings": {
      "href": "http://localhost:8181/api/people/1/meetings"
    }
  },
  "id": 1,
  "name": "Frida Kuvalis"
}

Meetings

GET /api/people/:personId/meetings

Response:

{
  "_links": {
    "self": {
      "href": "http://localhost:8181/api/people/1/meetings"
    }
  },
  "_embedded": {
    "meetings": [
      {
        "_links": {
          "self": {
            "href": "http://localhost:8181/api/people/1/meetings/1"
          }
        },
        "people": [
          {
            "id": 1,
            "ref": "http://localhost:8181/api/people/1"
          },
          {
            "id": 2,
            "ref": "http://localhost:8181/api/people/2"
          }
        ],
        "id": 1,
        "comment": "comment 1"
      },
      {
        "_links": {
          "self": {
            "href": "http://localhost:8181/api/people/1/meetings/2"
          }
        },
        "people": [
          {
            "id": 3,
            "ref": "http://localhost:8181/api/people/3"
          },
          {
            "id": 1,
            "ref": "http://localhost:8181/api/people/1"
          }
        ],
        "id": 2,
        "comment": "comment 2"
      }
    ]
  }
}

POST /api/people/:personId/meetings

Request:

{
  "otherPersonId": 2,
  "comment": "Some comment"
}

Response:

{
  "_links": {
    "self": {
      "href": "http://localhost:8181/api/people/1/meetings/1"
    }
  },
  "people": [
    {
      "id": 1,
      "ref": "http://localhost:8181/api/people/1"
    },
    {
      "id": 2,
      "ref": "http://localhost:8181/api/people/2"
    }
  ],
  "id": 1,
  "comment": "Some comment"
}

GET /api/people/:personId/meetings/:id

Response:

{
  "_links": {
    "self": {
      "href": "http://localhost:8181/api/people/1/meetings/1"
    }
  },
  "people": [
    {
      "id": 1,
      "ref": "http://localhost:8181/api/people/1"
    },
    {
      "id": 2,
      "ref": "http://localhost:8181/api/people/2"
    }
  ],
  "id": 1,
  "comment": "Some comment"
}

hypermedia-api-server's People

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.