Lightweight framework for building dynamic multi-level APIs for any provider (Express, socket.io, etc.), consumable via multiple channels (HTTP, socket.io, etc.)
- Dynamic model-based API routes
- Extensible API queries with pre- and post-query steps (coming soon)
- Transformations (via api-core-mapper or your own library)
- Authentication, ACL (via node-acl, passport, etc.)
- Multi level API routes (eg. /schools/42/students/3/courses)
- Multi channel APIs (eg. consuming HTTP and socket.io via api-provider packages)
- Multi database APIs (different database for every route, if you need)
- Versioned APIs
- Swagger compatibility (via api-core-mapper)
API Core is in
beta and NOT ready for production use.
To install the latest version, use NPM:
$ npm install api-core
In API Core every API is built from edges. An edge defines operations and relations of a Data Model.
Every edge provides the following operations:
- List entries (eg. GET /students)
- Get an entry (eg. GET /students/3)
- Create an entry (eg. POST /students)
- Replace/Update an entry (eg. PUT /students/3)
- Edit an entry (eg. PATCH /students/3)
- Remove an entry (eg. DELETE /students/3)
- Access to operations of one-to-one relations (eg. GET /students/3/class)
- Access to operations of one-to-many relations (eg. GET /schools/42/students/3/courses)
- Access to custom operations (eg. PUT /students/3/rename)
Every operation provides standard features like filtering, sorting, population and pagination.
Also every operation is available via all enabled channels.
So while you can list students via a HTTP request, you also can do the same via a socket.io message or any custom channel defined by you.
You can use API Providers to make your API consumable via different channels.
We have (or working on) providers for the following channels:
- socket.io: api-provider-socket.io (coming soon)
Also you can implement your own API provider.
Every API requires a set of data models. As with API Providers, you have a bunch of options when choosing your library for creating the models.
We have (or working on) data model libraries for the following frameworks:
- MongoDB: api-model-mongoose
Also you can implement your own API model library.
We have two working examples in the following repository, one with a local in-memory model (master branch) and one with a Mongoose model (mongodb branch).
Working Demo: api-demo
A complete API with 5 models and relations in 67 lines:
;;;;app = new Ellipse;mongoose.Promise = global.Promise;mongoose.connect"mongodb://localhost/api-demo";;classEdge =MongooseModelFactory.createModel"class", "classes",,courseEdge =MongooseModelFactory.createModel"course", "courses",,courseTypeEdge =MongooseModelFactory.createModel"courseType", "courseTypes",,schoolEdge =MongooseModelFactory.createModel"school", "schools",;= new Api'1.0'.edgestudentEdge;= new Api'1.1'.edgestudentEdge.edgeclassEdge.edgecourseEdge.edgecourseTypeEdge.edgeschoolEdge;app.userequire'body-parser'.json;;router.applyapp;app.listen8080;
We maintain high test coverage to provide a reliable framework for your APIs.
To run tests, execute the following NPM commands:
$ npm install$ npm test
The MIT License. Free forever. :)