MyNixOS website logo
Description

Simple Routing functions for Wai Applications.

purescheme-wai-routing-core

Build Status Hackage

The goal of purescheme is make a simple framework for building fast microservices and web applications in haskell.

This module provides simple routing functions for create rest APIs on top of a WAI server.

Getting Started

Minimal Example to run a helloworld using Warp server:

{-# LANGUAGE OverloadedStrings #-}
module Main where

import Network.Wai.Routing.Purescheme.Core

import Network.HTTP.Types (status200, StdMethod(..), hContentType)
import Network.Wai.Handler.Warp (run)
import Network.Wai (responseLBS, Application)

main :: IO ()
main = run 8080 api

api :: Application
api = path "hello"
            $ method GET
            $ complete
            $ responseLBS status200 [(hContentType, "text/html")] "<h1>Hellow World!</h1>"

Overview

This module provides simple routing functions that works on top of "Network.Wai" applications.

The basic idea is provides functions that modifies an @"Application" in order to match certain rules. It is inspired on akka http server Routing DSL.

User Guide

The API is divided in several modules by its functionality:

  • Network.Wai.Routing.Purescheme.Core.Basic provides the basic types and functionality including how to complete a request and exception handling.
  • Network.Wai.Routing.Purescheme.Core.Path routing functions that matches with the Path of the URI.
  • Network.Wai.Routing.Purescheme.Core.Query routing functions to extract parameters from the query part of the URI.
  • Network.Wai.Routing.Purescheme.Core.Method routing functions based on http method.
  • Network.Wai.Routing.Purescheme.Core.Entity routing and manipulation API related with Entity in the request and the response. Useful for content negotiation and serialization of entities.
  • Network.Wai.Routing.Purescheme.Core.Entity.Json concrete functions to operate on JSON encoding entities based on Aeson library.

A complete example can be found in the app folder.

Why

There are many routing frameworks for Haskell but they usually are:

  • They come with their own Monads or exoteric strategics to build routes.
  • Some of them are not using the type system properly

So, as Haskell is totally functional, and, based on the simplicity of an Wai Application (which is basically a function that converts requests to responses), why not create functions on top of Wai Application that provides a functional way to implement RESTful APIs?

Status

Currently the API is totally functional but the status is considered Alpha. That means, the API can change in further release until it reachs the beta status.

Feedback are welcome!

Please, if you feel that some functionallity is missing or something can be improve, post an issue or contact the author.

Metadata

Version

0.1.3.0

License

Executables (1)

  • bin/simple-routing-core-exe

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows