npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mysql-restapi

v1.2.6

Published

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

Downloads

33

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

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

/* 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",---}