0.0.21 • Published 5 years ago

crud-ws v0.0.21

Weekly downloads
3
License
GPLv3
Repository
github
Last release
5 years ago

CRUD-Oriented Web Services

This is a work-in-progress.

This is a simple library for quick development of Express web service endpoints. In particular it makes development of back line CRUD API's easy.

Entity and EntityFactory are defined as interfaces, so as to be able to plug in additional implementations. For the time being the only implementation is MongoDB.

Installation

npm i crud-ws

CRUD Routes

Creating the easiest server is as easy as:

const entityFactory = new MongoEntityFactory('mongodb://localhost:27017', 'myDb');
const entity: Entity = entityFactory.createEntityController('myCollection');

const server = new ExpressServer(3000);
server.addCrudRoute('/documents', entity);

This snippet of code will generate for you:

  • an Express server on port 3000
  • a /documents route with default methods:
    • GET /documents
    • GET /documents/:id
    • POST /documents/filter
    • POST /documents
    • PUT /documents
    • DELETE /documents/:id
  • error handling at all levels

CRUD Proxy Routes

CRUD-WS also provides a CrudProxyRoute, for an edge service proxying a CRUD endpoint.

	const server = new ExpressServer(3001)
	server.addCrudProxyRoute('/documents', 'http://localhost:3000/rest')

Standard routes

You can also add standard Express routes like this:

const router = express.Router()
router.get('/test', async (req, res) => {
	res.json({
		status: 202,
		message: 'Accepted'
	})
	
server.addRoute('/rest', router)
})
0.0.21

5 years ago

0.0.20

5 years ago

0.0.19

5 years ago

0.0.18

5 years ago

0.0.17

5 years ago

0.0.16

5 years ago

0.0.15

5 years ago

0.0.14

5 years ago

0.0.13

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago