# mysql-restapi

> Module for gateway between MySql DB & Rest API with features of cors & api generator. Option of login and custom sql query also available

Latest version **1.2.6** (published 2017-07-12) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install mysql-restapi
pnpm add mysql-restapi
yarn add mysql-restapi
bun add mysql-restapi
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.6 |
| Published | 2017-07-12 |
| First published | 2017-06-16 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Known vulnerabilities | 0 (+9 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Jitendra |
| Maintainers | jitendra5984 |
| Keywords | sql, mysql, rest, api, rest api, restapi, express, expressjs, cors, cross browser origin, node, npm, generator, crud, get, post, update, create, delete, table, service |

## Links

- npm: https://www.npmjs.com/package/mysql-restapi
- Repository: https://github.com/jitendra5984/mysql-restapi
- Homepage: https://github.com/jitendra5984/mysql-restapi#readme
- Issues: https://github.com/jitendra5984/mysql-restapi/issues
- npm.io page: https://npm.io/package/mysql-restapi

## Dependencies (5)

- [cors](https://npm.io/package/cors.md) ^2.8.3
- [mysql](https://npm.io/package/mysql.md) ^2.13.0
- [multer](https://npm.io/package/multer.md) ^0.1.8
- [express](https://npm.io/package/express.md) ~4.15.2
- [body-parser](https://npm.io/package/body-parser.md) ^1.12.4

## Alternatives

- [@lexical/table](https://npm.io/package/@lexical/table.md) — 3.0M weekly downloads
- [mantine-datatable](https://npm.io/package/mantine-datatable.md) — 98.2K weekly downloads
- [react-native-collapsible-tab-view](https://npm.io/package/react-native-collapsible-tab-view.md) — 70.6K weekly downloads
- [@handsontable/vue3](https://npm.io/package/@handsontable/vue3.md) — 16.1K weekly downloads
- [vuewordcloud](https://npm.io/package/vuewordcloud.md) — 7.2K weekly downloads

## Recent versions

- 1.2.6 (latest) — 2017-07-12
- 1.2.5 — 2017-07-04
- 1.2.4 — 2017-07-04
- 1.2.3 — 2017-07-04
- 1.2.2 — 2017-06-28
- 1.2.1 — 2017-06-28
- 1.2.0 — 2017-06-26
- 1.1.4 — 2017-06-23
- 1.1.3 — 2017-06-23
- 1.1.2 — 2017-06-21
- 1.1.1 — 2017-06-21
- 1.1.0 — 2017-06-21
- 1.0.2 — 2017-06-19
- 1.0.1 — 2017-06-16
- 1.0.0 — 2017-06-16

## README

# mysql-restapi

Module for gateway between MySql DB & RestAPI.

Express framework & mysql package required for database connection.

## API

### Before Installation
Make sure you have setup express project
Go [here](https://expressjs.com/) to find out more 

Make sure mysql module is instsalled before installing mysql-restapi, or install it

`$ npm install mysql --save`

### Installation

`$ npm install mysql-restapi`

First load express and mysql

```js
var express = require('express');
var mysql = require('mysql');
var mysqlrestapi  = require('mysql-restapi');
var dbconfig = require('./connections');
var app = express();
var api = mysqlrestapi(app, dbconfig);

```
Create file named connections.js on root

```js
/* Create database connetion */
var mysql = require('mysql');
var connection=mysql.createPool({
    host:'localhost',
    user:'DBUSER',
    password:'DBPASSWORD',
    database:'DATABASE'
});

/* Setting parameters for API url customization */
var settingOptions = {
    apiURL:'api', // Custom parameter to create API urls
    paramPrefix:'_' // Parameter for field seperation in API url
};

/* Setting options to handle cross origin resource sharing issue */
var corsOptions = {
  origin: "*", // Website you wish to allow to connect
  methods: "GET, POST, PUT, DELETE", // Request methods you wish to allow
  preflightContinue: false,
  optionsSuccessStatus: 200,
  allowedHeaders: "Content-Type", // Request headers you wish to allow
  credentials: true // Set to true if you need the website to include cookies in the requests sent
};

module.exports={connection, settingOptions, corsOptions};
```

# How to use

After completing setup given above follow these options to run APIs:

## CRUD (GET, POST/CREATE, PUT/UPDATE, DELETE) request APIs


Request Method | Request URL                            | Purpose                      | Parameters
-------------  | -------------------------------------  | ---------------------------  | -------------
GET            | YOUR_DOMAIN/api/crud/:tablename        | Fetch full table             | - 
GET            | YOUR_DOMAIN/api/crud/:tablename/:rowID | Fetch record via Row ID      | - 
POST           | YOUR_DOMAIN/api/crud/:tablename        | Create/Enter record in table | {"fieldname":"fieldvalue",---} 
PUT            | YOUR_DOMAIN/api/crud/:tablename/:rowID | Update record via ID         | {"fieldname":"fieldvalue",---}  
DELETE         | YOUR_DOMAIN/api/crud/:tablename/:rowID | Delete record via Row ID     | - 


## APIs to fetch data

Request Method | Request URL                                                           | Purpose                     
-------------  | -------------------------------------                                 | --------------------------- 
GET            | YOUR_DOMAIN/api/crud/:tablename?_limit=0,100                          | Passing limit in result            
GET            | YOUR_DOMAIN/api/crud/:tablename?_order[fieldname]=DESC                | Sort order in result            
GET            | YOUR_DOMAIN/api/crud/:tablename?_fields=fieldname1,fieldname2         | Fetch selected fields            
GET            | YOUR_DOMAIN/api/crud/:tablename?fieldname[LIKE]=%fieldvalue%          | Like query, varry % position      
GET | YOUR_DOMAIN/api/crud/:tablename?_limit=0,100&_order[fieldname ]=DESC&_fields=fieldname1,fieldname2fieldname[LIKE]=%fieldvalue% | All together      


## Custom query request APIs


Request Method | Request URL                     | Purpose                          | Parameters
-------------  | ------------------------------  | -------------------------------  | -------------
GET            | YOUR_DOMAIN/api/custom/:query   | Run custom query & get result    | - 
POST           | YOUR_DOMAIN/api/custom          | Run custom query & get result    | {"query":"SQL_QUERY"} 


## Login/check fields Post API


Request Method | Request URL                     | Purpose                          | Parameters
-------------  | ------------------------------  | -------------------------------  | -------------
POST           | YOUR_DOMAIN/api/check/:tablename | Check records availablity status | {"fieldname":"fieldvalue",---}

---
_Source: https://npm.io/package/mysql-restapi · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
