Skip to content

Instantly share code, notes, and snippets.

@TyrfingMjolnir
Last active December 12, 2018 22:43
Show Gist options
  • Save TyrfingMjolnir/834a433cbd04b6d77f13c7bd05d068f6 to your computer and use it in GitHub Desktop.
Save TyrfingMjolnir/834a433cbd04b6d77f13c7bd05d068f6 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
const
express = require( 'express' ),
app = express(),
passport = require( 'passport' ),
LocalStrategy = require( 'passport-local' ).Strategy,
bodyParser = require( 'body-parser' );
app.use( bodyParser.urlencoded( { extended: true } ) );
app.use( bodyParser.json() );
const port = process.env.PORT || 8090;
app.use( '/item', require( './route/item' ) );
app.listen( port );
console.log( 'Magic happens on port ' + port );
module.exports = app;
{
"name": "restapi",
"version": "6.6.7",
"description": "RestAPI template",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "ssh",
"url": "/opt/local/restapi"
},
"keywords": [
"mssql"
],
"author": "ggt667",
"license": "MIT",
"dependencies": {
"express": "*",
"passport": "*",
"passport-local": "*",
"pg": "*",
"pg-native": "*",
"tedious": "*"
}
}
const
express = require( 'express' ),
node = express.Router();
node.post( '/', function( req, res, next ) {
res.json({ message: 'You did an HTTP POST query' });
next();
}).get( '/', function( req, res, next ) {
res.json({ message: 'You did an HTTP GET query' });
next();
}).post( '/:id', function( req, res, next ) {
res.json({ message: 'You did an HTTP POST query',
arg: req.params });
next();
}).get( '/:id', function( req, res, next ) {
res.json({ message: 'You did an HTTP GET query',
arg: req.params });
next();
}).put( '/:id', function( req, res, next ) {
res.json({ message: 'You did an HTTP PUT query',
arg: req.params });
next();
}).patch( '/:id', function( req, res, next ) {
res.json({ message: 'You did an HTTP PATCH query',
arg: req.params });
next();
}).delete( '/:id', function( req, res, next ) {
res.json({ message: 'You did an HTTP DELETE query',
arg: req.params });
next();
});
module.exports = node;
curl -sX POST http://localhost:8090/item | json && \
curl -sX GET http://localhost:8090/item | json && \
curl -sX POST http://localhost:8090/item/1 | json && \
curl -sX GET http://localhost:8090/item/2 | json && \
curl -sX PUT http://localhost:8090/item/3 | json && \
curl -sX PATCH http://localhost:8090/item/4 | json && \
curl -sX DELETE http://localhost:8090/item/5 | json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment