Giter VIP home page Giter VIP logo

rest-api-nodejs-mysql-crud-v2's Introduction

rest-api-nodejs-mysql-crud-v2

RestAPI template using NodeJS + Express + MySQL

Example to create RESTFul API for CRUD operations using MySQL as Database. Using Babel to transform modern Javascript syntax to versions that any browser can understand.

What you can do with this examples ?

You will be able to test the differents endpoints that I wrote and make the classics request methods as GET, POST, PUT and DELETE operations.

What knowledge do you need to understand this examples ?

You need to have basic knowledge of the technologies used in the creation. I use

  • NodeJS - As main language
  • Express - To have our server
  • MySQL - As database to store the data.

Installation

Download the project and open it in your code editor. And put on the console

npm install

npm start

If everything went well, you should see something like this on the console

Server Running in Port xxxx
Database Connected

In this point we are more than ready to make the tests!!

MySQL

Before make test check the file with name createcompanyDB.sql en run the commands in Workbench o console

Endpoints

For test in my case I use POSTMAN

Main URL: localhost:xxxx/company


This request will return the complete list of company. GET method: localhost:xxxx/company

The answer will be something like:

[
    {
        "id": 1,
        "first_name": "Flavio",
        "last_name": "Aro",
        "email": "[email protected]",
        "age": 33
    },
    {
        "id": 2,
        "first_name": "Teste",
        "last_name": "Teste",
        "email": "[email protected]",
        "age": 30
    }
]

This request will return only 1 company. GET by ID method: localhost:xxxx/company/id/:id

The answer will be something like:

{
    "id": 1,
    "first_name": "Flavio",
    "last_name": "Aro",
    "email": "[email protected]",
    "age": 33
}

This request will create a company. POST method: localhost:xxxx/company/add

The company information you enter on Postman should look something like:

{
    "first_name": "You new company name",
    "last_name": "company last name",
    "email": "[email protected]",
    "age": The company age as number value
}

This request will be able to update the data of a specific company. PUT method: localhost:xxxx/company/edit/:id

You can change the data of a specific company for example:

{
    "first_name": "Flavio",
    "last_name": "Aro",
    "email": "[email protected]",
    "age": 33
}

to:

{
    "first_name": "Flavio",
    "last_name": "Aro",
    "email": "[email protected]",
    "age": 33
}

This request will remove a specific company. DELETE by ID method: localhost:xxxx/company/delete/:id


This request will remove all records from the company table. DELETE method: localhost:xxxx/company/deletecompany


I hope this example is helpful to you. Feel free to use it or modify it to your liking. I will update it over time

rest-api-nodejs-mysql-crud-v2's People

Contributors

flavioaro 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.