Git Product home page Git Product logo

alex-arriaga / node-js-restful-api-example Goto Github PK

View Code? Open in Web Editor NEW
20.0 2.0 30.0 447 KB

An example about how to create a RESTful API using Express.js. The four CRUD operations are provided: create, read, update and delete records. This server keeps an array of JSON objects in memory and runs the CRUD operations on it. If the server is restarted everything returns to the initial configuration (12 event objects)

CSS 30.76% HTML 31.51% JavaScript 37.74%

node-js-restful-api-example's Introduction

Node.js RESTful API Example

An example about how to create a RESTful API using Express.js. The four CRUD operations are provided: create, read, update and delete records. This server keeps an array of JSON objects in memory and runs the CRUD operations on it. If the server is restarted everything returns to the initial configuration (12 event objects).

Installation

  1. Install Dependencies

  2. Go to the project's root directory cd /my/path/to/directory

  3. Run npm install

  4. Start using it! npm start

Available end-points

GET /events

Gets all the available events (12 sample events).

GET /events/:id

Obtains an event given its id.

POST /events

Creates an event (be sure you are sending the headers via your library).

Headers

Content-Type : application/json

Request body (raw)

    {
        "topics": "",
        "thumbnail": "/img/tr-3.jpeg",
        "url": "index.html",
        "overrideURL": "",
        "linkType": "",
        "title": "Created by Postman",
        "summary": "Lorem ipsum dolor sit amet"
    }

PUT /events/:id

Updates an existing event. The JSON object must be passed in the request body as raw. It returns an error in case the event doesn't exist.

Headers

Content-Type : application/json

Request body (raw)

    {
        "id": "1",
        "topics": "",
        "thumbnail": "/img/tr-3.jpeg",
        "url": "index.html",
        "overrideURL": "",
        "linkType": "",
        "title": "Updated by Postman",
        "summary": "Lorem ipsum dolor sit amet"
    }

DELETE /events/:id

Removes an event given its id.

node-js-restful-api-example's People

Contributors

alex-arriaga avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.