restful-typeorm v0.1.3
RESTful-TypeORM
RESTful-TypeORM is a library for Node to expose CRUD (Create, Retrieve, Update and Delete) operations on TypeORM Entity objects via REST API.
What Problem Does It Solve?
Making available relational data owned and managed by a service to other programs, such as other services or web applications running within a Browser, often involves writing boilerplate code to implement REST primitives to create, update, retrieve and delete data items. This library implements this functionality in a generic manner, utilizing the metadata available within the TypeORM Entities definitions, and hence greatly reduces the amount of code to be written for a typical service. Customization, such as different names of entities and their properties, blocking certain operations, pruning list of returned fields, custom authorization, auditing and other operations are still possible via programmer specified functions.
Features
- Support for CRUD (Create, Retrieve, Update, Delete) operations by natural mapping of REST operations to DB calls
- JSON input and output payloads
- Enahnced Listing of resources (via retrieve of Collection of entities) To be implemented
- Pagination
- Ordering
- Grouping
- Filtering
- ...
- Access of sub-resources (as in
Book/id/authorwhereauthora property of theBookentity, possibly a foreign-key intoAuthorentity) - Behavior customization via declarative means (decorators)
- Input validation against TypeORM Entity definition
- Out-of-box embeddings in a CLI and Express server
- Sample deployments as AWS Elastic BeanStalk and Serverless Lambda
- CORS support
- Metadata endpoints to generate Swagger documentations To be implemented
- Custom authorization and auditing To be implemented
Quick Start Guide
This software is in pre-alpha stage. Not recommended for production use.
To install this package make sure that your machine have a relatively recent version of Node and Yarn installed globally. Then perform following steps:
- Add
restful-typeormpackage to your project.
yarn add restful-typeorm- To see the software in action on a sample DB schema with SQLite DB, install
sqlitepackage, copynode_modules/examplesto your working directory and run the server with environment variableORMCONFIG_FILEset to the config file.
yarn add sqlite
cp -r node_modules/restful-typeorm/examples .
ORMCONFIG_FILE=./examples/sample1/ormconfig.json yarn rt-serverBy default, this server listens at port no. 5000. To use another value, set the environment variable PORT to that value, as in:
PORT=8080 ORMCONFIG_FILE=./examples/sample1/ormconfig.yml yarn rt-serverThe SQLite database file location is specified in the configuration file. By default, it is set to .db/sample1.db. You can modify the config. file to use any of the databases supported by TypeORM.
You can now issue curl commands to access the resources:
- List all books and authors:
curl http://localhost:5000/Book
curl http://localhost:5000/AuthorAs the DB is empty, the results will show empty lists.
- Create an
Authorresource:
curl -X POST -H 'Content-Type: application/json' -d '{"name": "Donald Knuth"}' http://localhost:5000/Author- List a specific resource by id:
curl http://localhost:5000/Author/1- Update the newly created
Authorresource:
curl -X PATCH -H 'Content-Type: application/json' -d '{"name": "Donald E. Knuth"}' http://localhost:5000/Author/1- Create another
Authorresource:
curl -X POST -H 'Content-Type: application/json' -d '{"name": "JK Rowling"}' http://localhost:5000/Author- List all
Authorresources:
curl http://localhost:5000/Author- Delete an
Authorresource:
curl -X POST http://localhost:5000/Author/1User Guide
TBD