All Projects → rill-js → Rill

rill-js / Rill

Licence: mit
🗺 Universal router for web applications.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Rill

Webpack Isomorphic Dev Middleware
The webpack-dev-middleware, but for isomorphic applications
Stars: ✭ 38 (-92.98%)
Mutual labels:  middleware, universal, isomorphic
Minrouter
a micro middleware router for isomorphic javaScript web apps
Stars: ✭ 159 (-70.61%)
Mutual labels:  universal, isomorphic, router
Frontexpress
An Express.js-Style router for the front-end
Stars: ✭ 263 (-51.39%)
Mutual labels:  middleware, router
Go Starter Kit
[abandoned] Golang isomorphic react/hot reloadable/redux/css-modules/SSR starter kit
Stars: ✭ 2,855 (+427.73%)
Mutual labels:  universal, isomorphic
Isomorphic Webpack
Abstracts universal consumption of application code base using webpack.
Stars: ✭ 294 (-45.66%)
Mutual labels:  universal, isomorphic
Franxx
A vanilla JavaScript router that works everywhere.
Stars: ✭ 255 (-52.87%)
Mutual labels:  universal, router
Zen
zen is a elegant and lightweight web framework for Go
Stars: ✭ 257 (-52.5%)
Mutual labels:  middleware, router
Jackblog React
Jackblog react 版, 个人博客系统, 使用服务端渲染(Universal / Isomorphic), react, redux, react-router, react-bootstrap, immutablejs, redux-form等
Stars: ✭ 292 (-46.03%)
Mutual labels:  universal, isomorphic
webpack-isomorphic-compiler
A compiler that makes your life easier if you are building isomorphic webpack powered apps, that is, single page applications with server-side rendering
Stars: ✭ 16 (-97.04%)
Mutual labels:  isomorphic, universal
Krakend
Ultra performant API Gateway with middlewares. A project hosted at The Linux Foundation
Stars: ✭ 4,752 (+778.37%)
Mutual labels:  middleware, router
Miox
Modern infrastructure of complex SPA
Stars: ✭ 374 (-30.87%)
Mutual labels:  middleware, router
Diet
A tiny, fast and modular node.js web framework. Good for making fast & scalable apps and apis.
Stars: ✭ 394 (-27.17%)
Mutual labels:  middleware, router
koa-rest-router
Most powerful, flexible and composable router for building enterprise RESTful APIs easily!
Stars: ✭ 67 (-87.62%)
Mutual labels:  middleware, router
FlipED
A LMS built specifically for Thailand's Education 4.0 system.
Stars: ✭ 24 (-95.56%)
Mutual labels:  isomorphic, universal
Curi
A JavaScript router for single-page applications
Stars: ✭ 262 (-51.57%)
Mutual labels:  universal, router
react-ssr-spa
Server side rendered single page app using reactjs official libraries.
Stars: ✭ 30 (-94.45%)
Mutual labels:  isomorphic, universal
Simple Php Router
Simple, fast and yet powerful PHP router that is easy to get integrated and in any project. Heavily inspired by the way Laravel handles routing, with both simplicity and expand-ability in mind.
Stars: ✭ 279 (-48.43%)
Mutual labels:  middleware, router
Iris
The fastest HTTP/2 Go Web Framework. AWS Lambda, gRPC, MVC, Unique Router, Websockets, Sessions, Test suite, Dependency Injection and more. A true successor of expressjs and laravel | 谢谢 https://github.com/kataras/iris/issues/1329 |
Stars: ✭ 21,587 (+3890.2%)
Mutual labels:  middleware, router
redux-pluto
redux pluto
Stars: ✭ 75 (-86.14%)
Mutual labels:  isomorphic, universal
react-ssr-starter
📚 Featuring Webpack 4, React 17-18, SSR, HMR, prefetching, universal lazy-loading, and more
Stars: ✭ 18 (-96.67%)
Mutual labels:  isomorphic, universal

Rill Logo
API stability TypeScript NPM version Build status Test Coverage Downloads Browser Bundle Size (Gzipped) Gitter Chat Sauce Test Status

Expressive router for nodejs and the browser. Rill brings cascading middleware to the browser and enables a familiar routing solution for web applications.

Rill provides the minimum for abstractions over nodejs and the browser enabling things like routing (with redirecting, refreshes and more), cookies, and middleware with the same api.

It supports many view engines including Marko, React, Svelte and even html only template engines such as Pug.

Installation

npm install rill

Browser support

All modern browsers are supported including IE10 and above. Older browsers will need to polyfill the Promise API, checkout es6-promise for a good polyfill, babel-polyfill also covers this.

Community

Articles

Why Rill?

Rill is the answer to a simple question; Can I run my Express style router in the browser? Turns out you can and it works awesome.

It brings a common interface to many typical app like features in both the browser and nodejs. Many isomorphic frameworks and routers have crazy abstractions and learning curves but with Rill, if you understand Express or Koa, you already know how the routing works! In Rill you get to program much of your application logic using the same api (client or server) including routing, rendering, data fetching and more are easily shared.

Rill also works perfectly as a stand alone router for nodejs or in the browser. This allows for easy progressive enhancement. If all is well the browser can handle much of your application logic and if JavaScript fails for any reason your server knows exactly what to do.

How does this thing work?

If you look at the source for Rill here you will quickly notice there is ZERO browser specific code. This is all thanks to @rill/http which is node's HTTP.createServer ported to the browser.

In the browser it works by listening for internal link clicks, form submissions and browser history changes. It will then create a Rill Context for each of these events and emit it through the router, similar to how receiving a request works in nodejs.

It supports everything you'd expect from a client side nodejs server. This includes redirects, refreshes, cookies, scrolling and url updates using the History API.

Example

Create an app

/**
 * The following code can run 100% in the browser or in nodejs.
 * Examples use es2015/2016 with Babel and JSX but this is optional.
 */

import Rill from 'rill'
const app = new Rill() // You can call Rill without new, but autocomplete will not work.

Setup middleware

// Universal form data parsing middleware.
import bodyParser from '@rill/body'
app.use(bodyParser())

// Universal react rendering middleware.
import reactRenderer from '@rill/react'
app.use(reactRenderer())

// Example Logger
app.use(async ({ req }, next)=> {
  const start = Date.now()

  // Rill uses promises for control flow.
  // ES2016 async functions work great as well!
  await next()

  const ms = Date.now() - start
  console.log(`${req.method} ${req.url} - ${ms}`)
})

Setup a page

// Respond to a GET request.
app.get('/todos', async ({ res })=> {
  // Fetch a todolist from some service.
  const todolist = await MyTodoListService.getAllTodos()

  // Directly set React virtual dom to the body thanks to @rill/react.
  // (Checkout @rill/html for universal html diffing).
  res.body = (
    <html>
      <head>
        <title>My App</title>
        <meta name="description" content="Rill Application">
      </head>
      <body>
        <form action="/add-todo" method="POST">
          <h1>Just a plain old form</h1>
          <input type="text" name="todo"/>
          <button type="submit">Add Todo</button>
        </form>

        {todolist.length
          ? todolist.map(renderTodo)
          : 'No todos to display.'
        }
        <script src="/app.js"/>
      </body>
    </html>
  )
})

Handle a form submission

// Respond to a POST request.
app.post('/add-todo', async ({ req, res })=> {
  // We handle form submissions with Rill the same way one would express or koa.
  // Here we are simply adding the todo via some service.
  await MyTodoListService.addTodo({ text: req.body.todo })
  // And then we redirect back (same as res.redirect('/todos'))
  res.redirect('back')
})

Start app

// Start a regular http server.
// In the browser any form submissions or link clicks will intercepted by @rill/http.
app.listen({ port: 80 })

See Also

  • isbrowser - A browserify transform to remove server-side code.
  • isomorphic-fetch - Universal http requests using WHATWG fetch.
  • isomorphic-form-data - Send multipart form data universally (able to send files and works with fetch).
  • scroll-behavior - @rill/http will automatically try to use the "smooth" scroll-behavior when scrolling to targets on link clicks. This will polyfill that across modern browsers.
  • submit-form - Manually trigger Rill navigation in the browser.

Prior Art

  • koa-client - Koa clone that runs in the browser, inspired this package.
  • monorouter - Another isomorphic router that partially inspired this package.

Contributions

  • Use npm test to build and run tests.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].