Coder Social home page Coder Social logo

simple_express_framework's Introduction

My Own Express Framework

Hello there! This is my my express framework, made from the pure vanilla node.

Usage

Installation: npm install -g simple_express_framework

Then in your code: Just as simple as three lines of code, a RESTFUL web server is good to go.

var myExpress = require('simple_express_framework');
myExpress.addResources('unicorns');
myExpress.addResources('footballs'); // you can add whatever resource you need
myExpress.startServer(4000); // take port number that you want

// json data is stored at server root directory /data/<your resource>/id.json

Test the server

You can use superagent-cli or any other http request utility to test the server.

superagent <url> <rest method(get|post|put|patch|delete)> <json data>

Http request/response format

It supports http request <get|post|put|patch|delete>.

For put, post and patch, the Json data is sent along with the request, saved or modified json data sent back as a data property in a json object as response body if success. Other wise, error message will be included in the return response.body and data property is set to null.

//json data in the request:
{ 	key1: value1,
	key2: value2,
	key3: value3
}

// json data in the response:
{	msg: "Successful|Invalid request|Internal server error"
	data: 	// or modified data with patch request
		{	key1: value1,  
			key2: value2,
			key3: value3
		}
}

For get and delete, no data is sent along the request, the response data contains indicating the request/response status and json data for get request and null for delete request.

//no json data in the request:

// json data in the response:
{	msg: "Successful|Invalid request|Internal server error"
	data: 	// for "get" request and "null" for delete request
		{	key1: value1,  
			key2: value2,
			key3: value3
		}
}

Internal components (for reference only)

There are four modules in my express framework:

index.js			// The package main js file
httpServer.js 	// Server related configuration and creation
Router.js			// Handle resources based on the request method
dataSourcePlain	// Deal with the json data store, currentlly support flat file store, can be easily swapped out to use mongodb database.

Credits

Give credits to instructors and members in CodeFellow Fullstack Javascript for those helpful discussion and suggestion.

simple_express_framework's People

Contributors

chengzh2008 avatar

Watchers

James Cloos 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.