Code Monkey home page Code Monkey logo

chicken-express's Introduction

Chicken-express

A FastCGI web framework in Chicken Scheme, based on the API of Express for Node.js.

Plenty is missing right now and some parts will likely not make it in at all, but I hope to end up with a solid framework for building future Chicken web apps.

Requirements

A few modules are required which can be installed with chicken-install, as well as Chicken itself. Notable modules are:

  • protobj
  • uri-common
  • matchable
  • fastcgi
  • base64 (for middleware-favicon)
  • colorize (for the example)

Usage

A small example is included as example.scm. You can run this with:

CHICKEN_ENV=development ./example.scm

This will start a simple FastCGI server at port 3000 by default. The port can be changed by doing:

CHICKEN_ENV=development ./example.scm --port <port>

Alternatively the framework is designed to be compatible with shared socket managers such as Einhorn by passing a file descriptor instead of port:

CHICKEN_ENV=development einhorn -c chicken-express ./example.scm --fd srv:127.0.0.1:3000,so_reuseaddr

This allows you to add/remove workers at runtime. I am also planning on Circus support, but it is not currently working due to some file descriptor issues.

Hello World

The hello world should feel familiar to anyone that has used Express:

#!/usr/bin/csi -script

(load "chicken-express.scm")
(import chicken-express)

(load "middleware/logger.scm")
(import middleware-logger)

(define app (chicken-express))

{@app.use (middleware-logger)}

{@app.get "/" (lambda (self request response next)
                 {@response.send "Hello, world!"})}

{@app.listen 3000}

HACKING

This module (chicken-express.scm) is using protobj for its objects, and so the API currently uses its macros as well.

Things starting with "%" (variables, methods, etc) are internal to the module. Everything else is in theory a part of the public API exposed by the module.

To understand the code, start at the (chicken-express) method, followed by (! <app> listen) further down, and go from there.

chicken-express's People

Contributors

zanea avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

chicken-express's Issues

Refactor middleware/route handling

Right now middleware and regular routes are thrown into a single bag and it is messy to handle. I should refactor this code to build regular routes as a type of middleware, and then only deal with the underlying middleware to simplify things.

Support alternative webservers

Right now chicken-express uses the fastcgi egg, which I connect to a local nginx instance. This is for my convenience but there isn't a particular reason for it, so it would be nice to extract that out and allow a full scheme web server to sit in its place (while of course leaving the same end-user API).

Handle JSON as POST body

The body-parser middleware should recognize when it is being sent JSON in the body of a request and parse that instead of treating the data as begin form encoded.

This coincides with the need for robust handling of "Accept" headers and returning a correct "Content-type" to the browser.

Build a decent example

I should build a modern looking, and actually useful example for demonstrating chicken-express. For example I wanted to use Bootstrap for the included example but didn't want to clutter up the repository, so I should create a Chicken-express-example repository.

Revisit using local modules

Need to look at how other Chicken scheme libraries handle using local modules. Right now I am include-ing the module and then import-ing it but I would like to make this a single step.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.