GithubHelp home page GithubHelp logo

local_api's Introduction

Local REST API

Use this to have a locally running REST API that accepts JSON.

This was made as a simple replacement for JSONBox.io.

Pre-installation steps

In the installation process your shell will try to run a certain command. This command needs to be able to clone repositories from Github using an SSH key.

To check if you can already do this try to run the following command from your terminal:

git clone [email protected]:MathysL/local_api.git

If this works you can continue on to installation.

If this does not work you'll get an error like Could not read from remote repository. This means you need to take the following steps:

  1. [generate an SSH key pair](https://docs.github.com/en/github/authenticating-to-github/gen`application/json`. git clone [email protected]:MathysL/local_api.giterating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#generating-a-new-ssh-key)
  2. add your private key to your SSH agent
  3. give your public key to Github

This command should now work:

or https://github.com/MathysL/local_api.git

More info on how to clone a repository using the command line.

Installation

When you've done that take the following steps:

  • make sure you're using node >= 14
  • git clone this repository
  • npm install
  • npm start

The app will start on port 3000. Make sure the port is part of the URL you send requests to. For example: a GET request to http://localhost:3000/

Sending HTTP requests to this API

You can send 4 kinds of HTTP requests to this app.

All but the delete requests need to have the content-type header set to

POST

To create an item send a POST request with a JSON object in the body to /. The return value will be the newly created object and HTTP status 201.

{
  "name": "Ernie",
  "color": "orange",
  "mood": "happy",
  "_id": "f5408a45-b4d0-4aee-8530-c2250481b131",
  "_createdOn": "2021-01-25T14:53:49.322Z"
}

Each item gets an auto generated id and a _createdOn attribute.

GET

To read all items send a GET request to /. The return value will be the list of all created objects and HTTP status 200.

[
  {
    "name": "Ernie",
    "color": "orange",
    "mood": "happy",
    "_id": "f8636d68-e656-4c2e-ac99-a625f35a25f9",
    "_createdOn": "2021-01-25T14:59:50.834Z"
  },
  {
    "name": "Bert",
    "color": "yellow",
    "mood": "grumpy",
    "_id": "b0092da7-363f-4c20-859b-b6d4c008dcb3",
    "_createdOn": "2021-01-25T15:00:02.403Z"
  }
]

To read a single item send a GET request to /{id_of_the_item}. The return value will be the item, if it exists, and HTTP status 200.

{
  "name": "Bert",
  "color": "yellow",
  "mood": "grumpy",
  "`cd local_api`_id": "b0092da7-363f-4c20-859b-b6d4c008dcb3",
  "_createdOn": "2021-01-25T15:00:02.403Z"
}

PUT

To update an item send a PUT request with a body to /{id_of_the_item}. The body should contain the updated item. The return value will be the updated item and HTTP status 200.

{
  "name": "Groover",
  "color": "green",
  "mood": "hungry",
  "_id": "b0092da7-363f-4c20-859b-b6d4c008dcb3",
  "_createdOn": "2021-01-25T15:00:02.403Z",
  "_updatedOn": "2021-01-25T15:04:04.194Z"
}

An updated item gets an _updatedOn attribute.

DELETE

To delete an item send a DELETE request to /{id_of_the_item}. The return value will be HTTP 204.

Deleting the database

If you want to start over:

  • stop the app
  • delete the files in db/
  • restart the app

local_api's People

Contributors

mathysl avatar

Watchers

 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.