Giter Club home page Giter Club logo

crud-api's Introduction

CRUD-API

This a Lib. build to do basic crud Operations with nothing more than Node JS. The API allows you to create tokens and users to save with CRUD operations to any database.You can Create Users, and Manage tokens all with this API.No Packages, Only Native Node.Passwords are hashed with SHA 256 Encryption.Built in API with https and http test servers.No need to install anything just clone the repo CD into CRUD-API and Run Node Index.js. Can be installed through NPM as Lib. Build with simplicity,speed, and security in mind.To run file cd into index.js directory and run "node index.js". This will start Server, With options for Http/ and Https. can create users, tokens and store users and Data from API. Request Routes Below. Data Is converted to JSON for file saving and transfer.

Arguments and functions to use for Crud Operations if you want to write your own. Saves as JSON Data and JSON token.

Example Usage of Crud Operations API Routes and required Headers Below Crud Operations file.

Frist Import variable from ./lib/data

ex- var _data = require('./lib/data'); //Uses FS Native Node Module

The Arguments for Each Function must be provided to read and Write Data.

to Create a file must provide 4 arguments (dir, file, data, callback)

example- var _data = require('./lib/data');

_data.create('users',phone,userObject,function(err){ if(!err){ callback(200); } else { console.log(err); callback(500,{'Error' : 'Could not create the new user'}); } });

Read example- var _data = require('./lib/data');

to Read a file must provide 3 arguments (dir, file, callback)

_data.read('users',phone,function(err,data){ if(!err && data){ // do something and callback 200 when done; //return read Data Etc then 200 Status Code callback(200,data); } else { callback(404); } });

Update A File example- var _data = require('./lib/data'); to Update a a file must provide 3 arguments (dir, file,DataToUpdate, callback); Example // Store the new updates _data.update('users',phone,userData,function(err){ if(!err){ callback(200); } else { console.log(err); callback(500,{'Error' : 'Could not update the user.'}); } });

Delete Example var _data = require('./lib/data');

delete = function(dir,file,callback) As Arguments

_data.delete('users',phone,function(err){ if(!err){ //Remove Some File and Return 200 to know the process worked. callback(200); } else { callback(500,{'Error' : 'Could not delete the specified user'}); }

Routes For API- To Create/ Remove/ Delete/ Add Users to Data Base ( some Routes MUST have JSON TOKEN) from Token Route

/ping- Returns code 200 if running correctly /users- acceptableMethods = ['post','get','put','delete']) /Tokens acceptableMethods = ['post','get','put','delete'];

       Users - post (to Create)
         // Required data on Headers: firstName, lastName, phone, password, tosAgreement
       Users - get 
         // Required data on Headers : phone (Must have token to request user for auth) 
         
      Users - Delete 
        //  Requires Token From Tokens Route to Remove a User
        
     Users - Put 
         // Must Have Token to Update User Information 
        //Required data: phone
        // Optional data: firstName, lastName, password (at least one must be specified)

/Tokens acceptableMethods = ['post','get','put','delete']; Tokens - post // Required data: phone, password // Optional data: none handlers._tokens.post = function(data,callback)

// Tokens - get // Required data: id // Optional data: none handlers._tokens.get

Tokens - put // Required data: id, extend // Optional data: none

// Tokens - delete // Required data: id // Optional data: none handlers // Check that id is valid //then Can Delete

If there are any questions on using this API or anyone would like to contribute please send me an email or message [email protected]

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.