okapi: A bidirectional HTTP description language

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

Please see the README on GitHub at https://github.com/monadicsystems/okapi#readme


[Skip to Readme]

Properties

Versions 0.1.0.0, 0.1.0.1, 0.1.0.2, 0.2.0.0
Change log ChangeLog.md
Dependencies aeson (>=2.2 && <2.3), base (>=4.20.0.0 && <4.21), bytestring (>=0.12 && <0.13), case-insensitive (>=1.2 && <1.3), cookie (>=0.5 && <0.6), http-api-data (>=0.7 && <0.8), http-client (>=0.7 && <0.8), http-media (>=0.8 && <0.9), http-types (>=0.12 && <0.13), insert-ordered-containers (>=0.2 && <0.3), lucid (>=2.11 && <2.12), openapi3 (>=3.2 && <3.3), optics-core (>=0.4 && <0.5), profunctors (>=5.6 && <5.7), scientific (>=0.3 && <0.4), text (>=2.1 && <2.2), time (>=1.12 && <1.13), uuid (>=1.3 && <1.4), vector (>=0.13 && <0.14), wai (>=3.2 && <3.3) [details]
License BSD-3-Clause
Copyright 2026 Monadic Systems LLC
Author Monadic Systems LLC
Maintainer info@monadic.systems
Category Web
Home page https://github.com/monadicsystems/okapi#readme
Bug tracker https://github.com/monadicsystems/okapi/issues
Source repo head: git clone https://github.com/monadicsystems/okapi
Uploaded by rashad1030 at 2026-07-03T18:07:01Z

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for okapi-0.2.0.0

[back to package description]

🦓🦒Okapi

Okapi is a data-driven micro framework for implementing HTTP servers.

Hello World Example

helloWorld =
  responder @200 @'[] @Text.Text @Text.Text
    . method HTTP.GET id
    $ \greet _req -> return $ greet noHeaders "Hello World!"

main =
  Warp.run 8000
    . withDefault helloWorld
    $ \_ resp -> resp $ Wai.responseLBS HTTP.status404 [] "Not Found..."

Calculator Example

data Operator
    = Add
    | Sub
    | Mul
    | Div
    | Sq
    | Neg
    deriving (Show)

instance Web.FromHttpApiData Operator where
    parseUrlPiece "add" = Right Add
    parseUrlPiece "sub" = Right Sub
    parseUrlPiece "minus" = Right Sub
    parseUrlPiece "mul" = Right Mul
    parseUrlPiece "div" = Right Div
    parseUrlPiece "neg" = Right Neg
    parseUrlPiece "sq" = Right Sq
    parseUrlPiece "square" = Right Sq
    parseUrlPiece _ = Left "Can't parse operator..."

shared =
  lit "calc"
    . param @Operator
    . param @Int

unary =
  responder @200 @'[] @Text.Text @Int
    . responder @500 @'[] @Text.Text @Text.Text
    . method HTTP.GET id

unaryHandler operator x ok wrongArgs _req =
  return $ case operator of
    Sq  -> ok noHeaders (x * x)
    Neg -> ok noHeaders (x * (-1))
    _   -> wrongArgs noHeaders $ Text.pack (show operator) <> " needs two arguments."

binary =
  param @Int
    . responder @200 @'[] @Text.Text @Int
    . responder @500 @'[] @Text.Text @Text.Text
    . responder @403 @'[] @Text.Text @Text.Text
    . method HTTP.GET id

binaryHandler operator x y ok wrongArgs divByZeroErr _req =
  return $ case operator of
    Add -> ok noHeaders (x + y)
    Sub -> ok noHeaders (x - y)
    Mul -> ok noHeaders (x * y)
    Div ->
      if y == 0
      then divByZeroErr noHeaders "You can't divide by 0."
      else ok noHeaders (div x y)
    _ -> wrongArgs noHeaders $ Text.pack (show operator) <> " needs one argument."

calc = shared $ choice
  [ unary unaryHandler
  , binary binaryHandler
  ]

main =
  Warp.run 8003
    . withDefault calc
    $ \_ resp -> resp $ Wai.responseLBS HTTP.status404 [] "Not Found..."