Basic Overview
A Node.js fast, declarative framework for writing web servers, no taradiddles.
Philosophy:
-
Bliz is written with Concatenative Inheritance and RORO. I believe these are very powerful concepts, which lead to a more stable code base which in turn help build stable applications.
-
Bliz aims to provide a modular architecture approach out of the box for more maintanable, stable, readable code.
HTTP (implemented over Node's http module)
- Per route middlewares (express like and support existing express middlewars)
- Per route error handler
- Middleware timeouts (if a middleware was not completed in X seconds, continue or throw error)
- Global
app.inject()
method which helps you pass all your functions to any handler. - Optional validation on incoming requests using superstruct.js, a validation library.
- Swagger file auto generation, OpenAPI 3.0 spec (experimental)
- Pretty print all routes example of an http router:
Socket.io:
- Global
app.inject()
method which helps you pass all your functions to any handler. - Per socket handler middlewares with optional timeouts
- Pretty print all events
Graph QL (uses graphql-tools and graphql)
- Global
app.inject()
method which helps you pass all your functions to any handler. - Declarative schema creation with a simple function call
- Built in caching with DataLoader.js
- Integrated Graphiql for testing
- Declarative directive/enum/interface/union creation
- Microservices ready out of the box, thanks to GraphQL remote schema stitching
Table of contents
Installation
npm i -S blizoryarn add bliz
Usage
// if youre using es6 modulesor// if youre not using es2016 modulesconst Bliz = defaultconst app =
Http Server
a Bliz http server consists of 3 parts: path, router, global app let's see how to implement a simple http server.
// path.js { app // creates a new http path // creates a handler for the path // path middleware like in express }
// router.js { app }
// index.jsconst app = app
Writing this way is testable, modular and readable. Now fire a GET request to /api/example/path and enjoy.
Web Sockets
web sockets currently support and use socket.io behind the scenes. web sockets are handled differently in Bliz, they work the same as an http server, meaning an event is like a path, a router is a namespace of events with a delimiter, and the app combines all routers. lets see how this works
// event.js { app // creates a new socket listener // creates a handler for the event // yes, yes, events have middlewares as well, because why not ??? // abstraction usually helps readability }
// events-router.js {app event }
// index.jsconst app = app
Now if you fire an event to router:event it will pass through router middleware to route middleware to route handler, how cool is that ?
Graphql
Bliz uses graphql-tools and all the apollo packages to give you the easiest way to write graphql servers
we'll start with a schema:
// schema.jsconst schema = `type Post { name: String! id: Int! data: String} input newPost { name: String! id: Int! data: String}`
// resolver.jsconst resolver = Query: { return name:'some name' id:argsid } Post: { return postname } { return postid } { return postdata } postAdded: { return pubsub } { pubsub; return ...argsinput }
Notice Mutation and Subscription are functions injected with pubsub, Bliz creates a local pubsub instance to use with graphql-subscriptions, you can pass your own pubsub implementation, like redis pubsub in
app
Now, every time someone adds a post, who ever subscribes will get the updates, automatically! let's continue...
// create a graphql schema with our schema and resolver, define query// subscription and mutation { return app }
app
And voila, you do not need anything else to fire a full graphql server with subscriptions. Head to http://localhost:4000/graphiql - for testing playground Head to http://localhost:4000/graphql - for your graphql api Head to http://localhost:4000/subscriptions - for you real time goodness Back to top
Remote-schema-stitching
The graphql server we wrote just now can easily become part of a microservices style architecture without any changes, all we need to do is implement a gateway that wil stitch all responses and schemas for us.
const app = app
Head over to http://localhost:6000 and you will see all your schemas in one.
Notes
Bliz is in version 0.4.0 and I implemented it as a proof of concept to a declarative web server supporting all kinds of technologies. I do not recommend using it in production untill version 1.0.0 is released. There are a lot of things to add, change and so many tests to write! I hope people will get involved and we would create something awsome together.
Documentation
The examples shown here have only a fraction of the options included with Bliz, full documentation with every little detail coming soon! Help would be appreciated! Back to top
Contributing
If you decide to contribute, first of all thanks! steps:
- clone project
- npm install
- create a seperate branch for your ideas or features
- run prettier
- submit a pull request
License
The MIT License (MIT) 2018 - Yuri Khomyakov. Please have a look at the LICENSE.txt for more details.