All Projects → Theodus → Jennet

Theodus / Jennet

Licence: bsd-2-clause
A simple HTTP web framework written in Pony

Projects that are alternatives of or similar to Jennet

Rayo.js
Micro framework for Node.js
Stars: ✭ 170 (+136.11%)
Mutual labels:  router, http-server, webserver
Pure Http
✨ The simple web framework for Node.js with zero dependencies.
Stars: ✭ 139 (+93.06%)
Mutual labels:  router, http-server, webserver
Webserver
A C++ High Performance Web Server
Stars: ✭ 4,164 (+5683.33%)
Mutual labels:  http-server, webserver
Restana
Super fast and minimalist framework for building REST micro-services.
Stars: ✭ 341 (+373.61%)
Mutual labels:  http-server, webserver
Diet
A tiny, fast and modular node.js web framework. Good for making fast & scalable apps and apis.
Stars: ✭ 394 (+447.22%)
Mutual labels:  router, http-server
EthernetWebServer
This is simple yet complete WebServer library for AVR, Portenta_H7, Teensy, SAM DUE, SAMD21/SAMD51, nRF52, STM32, RP2040-based, etc. boards running Ethernet shields. The functions are similar and compatible to ESP8266/ESP32 WebServer libraries to make life much easier to port sketches from ESP8266/ESP32. Coexisting now with `ESP32 WebServer` and…
Stars: ✭ 118 (+63.89%)
Mutual labels:  webserver, http-server
httoop
HTTOOP - a fully object oriented HTTP protocol library written in python
Stars: ✭ 15 (-79.17%)
Mutual labels:  webserver, http-server
Nodemcu Httpserver
A (very) simple web server written in Lua for the ESP8266 firmware NodeMCU.
Stars: ✭ 369 (+412.5%)
Mutual labels:  http-server, webserver
phpkoa
PHP异步编程: 基于 PHP 实(chao)现(xi) NODEJS web框架 KOA。
Stars: ✭ 52 (-27.78%)
Mutual labels:  webserver, http-server
Iodine
iodine - HTTP / WebSockets Server for Ruby with Pub/Sub support
Stars: ✭ 720 (+900%)
Mutual labels:  http-server, webserver
Hydra
后端一站式微服务框架,提供API、web、websocket,RPC、任务调度、消息消费服务器
Stars: ✭ 407 (+465.28%)
Mutual labels:  http-server, webserver
Beetlex
high performance dotnet core socket tcp communication components, support TLS, HTTP, HTTPS, WebSocket, RPC, Redis protocols, custom protocols and 1M connections problem solution
Stars: ✭ 802 (+1013.89%)
Mutual labels:  http-server, webserver
restana
Super fast and minimalist framework for building REST micro-services.
Stars: ✭ 380 (+427.78%)
Mutual labels:  webserver, http-server
quickserv
Dangerously user-friendly web server for quick prototyping and hackathons
Stars: ✭ 275 (+281.94%)
Mutual labels:  webserver, http-server
Vedetta
OpenBSD Router Boilerplate
Stars: ✭ 260 (+261.11%)
Mutual labels:  router, http-server
rux
⚡ Rux is an simple and fast web framework. support route group, param route binding, middleware, compatible http.Handler interface. 简单且快速的 Go api/web 框架,支持路由分组,路由参数绑定,中间件,兼容 http.Handler 接口
Stars: ✭ 81 (+12.5%)
Mutual labels:  router, http-server
Cppwebframework
​The C++ Web Framework (CWF) is a MVC web framework, Open Source, under MIT License, using C++ with Qt to be used in the development of web applications.
Stars: ✭ 348 (+383.33%)
Mutual labels:  http-server, webserver
Embedio
A tiny, cross-platform, module based web server for .NET
Stars: ✭ 1,007 (+1298.61%)
Mutual labels:  http-server, webserver
Jarvis
APL-based web service framework supporting JSON or REST
Stars: ✭ 17 (-76.39%)
Mutual labels:  webserver, http-server
stirfry
StirFry is a self contained and lightweight web framework for nodejs
Stars: ✭ 24 (-66.67%)
Mutual labels:  webserver, http-server

jennet CircleCI

A simple HTTP web framework written in Pony

Features

  • Context: Store data that can be used by the request handler as well as any middleware.

  • Middleware Chaining: Easily add multiple middlewares to the route that can execute functions both before and after the request handler.

  • Explicit Route Matches: A request can only match exactly one or no route so that there are no unintended matches.

  • Route Parameters: Allow the router to parse the incoming URL path for you by specifying a route parameter. The router will then store a dynamic value in the context.

  • File Server: Easily serve static files and set custom NotFound handlers.

Usage

Installation

  • Install corral
  • corral add github.com/theodus/jennet.git
  • corral fetch to fetch your dependencies
  • use "jennet" to include this package
  • corral run -- ponyc to compile your application

Named Parameters

use "http_server"
use "jennet"

actor Main
  new create(env: Env) =>
    let auth =
      try
        env.root as AmbientAuth
      else
        env.out.print("unable to use network.")
        return
      end

    let server =
      Jennet(auth, env.out)
        .> get("/", H)
        .> get("/:name", H)
        .serve(ServerConfig(where port' = "8080"))

    if server is None then env.out.print("bad routes!") end

primitive H is RequestHandler
  fun apply(ctx: Context): Context iso^ =>
    let name = ctx.param("name")
    let body =
      "".join(
        [ "Hello"; if name != "" then " " + name else "" end; "!"
        ].values()).array()
    ctx.respond(StatusResponse(StatusOK), body)
    consume ctx

As you can see, :name is a named parameter. The values are accessible via the Context. In this example :name can be retrieved by c.param("name").

Named parameters only match a single path segment:

Path: /user/:username

 /user/jim                 match
 /user/greg                match
 /user/greg/info           no match
 /user/                    no match

There are also catch-all parameters that may be used at the end of a path:

Pattern: /src/*filepath

 /src/                       match
 /src/somefile.html          match
 /src/subdir/somefile.pony   match

The router uses a compact prefix tree algorithm (or Radix Tree) since URL paths have a hierarchical structure and only make use of a limited set of characters (byte values). It is very likely that there are a lot of common prefixes, which allows us to easily match incoming URL paths.

see also: julienschmidt/httprouter

Using Middleware

use "collections"
use "http_server"
use "jennet"

actor Main
  new create(env: Env) =>
    let auth =
      try
        env.root as AmbientAuth
      else
        env.out.print("unable to use network.")
        return
      end

    let handler =
      {(ctx: Context, req: Request): Context iso^ =>
        ctx.respond(StatusResponse(StatusOK), "Hello!".array())
        consume ctx
      }

    let users = recover Map[String, String](1) end
    users("my_username") = "my_super_secret_password"
    let authenticator = BasicAuth("My Realm", consume users)

    let server =
      Jennet(auth, env.out)
        .> get("/", handler, [authenticator])
        .serve(ServerConfig(where port' = "8080"))

    if server is None then env.out.print("bad routes!") end

This example uses Basic Authentication (RFC 2617) with the included BasicAuth middleware.

Serving Static Files

use "http_server"
use "jennet"

actor Main
  new create(env: Env) =>
    let auth =
      try
        env.root as AmbientAuth
      else
        env.out.print("unable to use network.")
        return
      end

    let server =
      try
        Jennet(auth, env.out)
          .> serve_file(auth, "/", "index.html")?
          .serve(ServerConfig(where port' = "8080"))
      else
        env.out.print("bad file path!")
        return
      end

    if server is None then env.out.print("bad routes!") end

Serving Static Directory

use "http_server"
use "files"
use "jennet"

actor Main
  new create(env: Env) =>
    let auth =
      try
        env.root as AmbientAuth
      else
        env.out.print("unable to use network.")
        return
      end

    let server =
      try
        Jennet(auth, env.out)
          // a request to /fs/index.html would return ./static/index.html
          .> serve_dir(auth, "/fs/*filepath", "static/")?
          .serve(ServerConfig(where port' = "8080"))
      else
        env.out.print("bad file path!")
        return
      end

    if server is None then env.out.print("bad routes!") end
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].