spirit-js / spirit

Modern modular library for building web applications
http://spirit.function.run
ISC License
244 stars 18 forks source link
functional http promise spirit web-framework

spirit

Modern and functional approach to building web applications.

Build Status Coverage Status Join the chat at https://gitter.im/spirit-js/spirit

Why?

const {adapter} = require("spirit").node
const route = require("spirit-router")
const http = require('http')

const hello = () => "Hello World!"

const greet = (name) => `Hello, ${name}`

const app = route.define([
  route.get("/", hello),
  route.get("/:name", ["name"], greet),
])

http.createServer(adapter(app)).listen(3000)

If we think about a web request in its simplest form, it's basically a function, it takes an input (request) and returns an output (response). So why not write web applications this way?

No more req, res. Spirit simplifies everything by abstracting away the complexity of req and res that normally resulted in impure and complex functions.

Middleware in spirit can also transform the returned response and not just the request. This is in contrast to other web libraries that can only transform the request. This is a simple idea but having this feature allows for much more DRY and expressive code.

Given the above, it's much more easier to re-use, test, and reason about your code in spirit.

Oh yea, most Express middleware works in spirit too!

Getting Started

The Handbook

Components

Third Party Components

Contributing

All contributions are appreciated and welcomed.

For backwards incompatible changes, or large changes, it would be best if you opened an issue before hand to outline your plans (to avoid conflict later on).

This codebase avoids using unnecessary semi-colons, camelCase and one-liners.

To run tests, use make test. This will also build changes to src/*, if you do not have make installed, you can look at the Makefile to see the steps to accomplish the task.

Credits

Spirit is heavily influenced by the design of Ring.