All Projects → unrelentingtech → Magicbane

unrelentingtech / Magicbane

Licence: unlicense
A web framework that integrates Servant, EKG, fast-logger, wai-cli…

Programming Languages

haskell
3896 projects

Projects that are alternatives of or similar to Magicbane

Cakephp
CakePHP: The Rapid Development Framework for PHP - Official Repository
Stars: ✭ 8,453 (+7250.43%)
Mutual labels:  web-framework
Tapestry 5
Mirror of Apache Tapestry 5
Stars: ✭ 87 (-24.35%)
Mutual labels:  web-framework
Wicket Tutorial Examples
Code examples for the offcial Wicket user guide
Stars: ✭ 104 (-9.57%)
Mutual labels:  web-framework
Fastplaz
FastPlaz - Pascal Web Framework
Stars: ✭ 72 (-37.39%)
Mutual labels:  web-framework
Jkmvc
Jkmvc is an elegant, powerful and lightweight MVC & ORM framework built using kotlin. It aims to be swift, secure, and small. It will turn java's heavy development into kotlin's simple pleasure. No spring.
Stars: ✭ 86 (-25.22%)
Mutual labels:  web-framework
Jooby
The modular web framework for Java and Kotlin
Stars: ✭ 1,309 (+1038.26%)
Mutual labels:  web-framework
Ktor
Framework for quickly creating connected applications in Kotlin with minimal effort
Stars: ✭ 9,190 (+7891.3%)
Mutual labels:  web-framework
Alchemy
Elegant, batteries included web framework for Swift.
Stars: ✭ 108 (-6.09%)
Mutual labels:  web-framework
Prairie
Get web applications growing in R
Stars: ✭ 86 (-25.22%)
Mutual labels:  web-framework
Cottage
Simple, fast HTTP router on koa.js.
Stars: ✭ 103 (-10.43%)
Mutual labels:  web-framework
Toruk
Go web 开发脚手架
Stars: ✭ 78 (-32.17%)
Mutual labels:  web-framework
Ofbiz Plugins
Apache OFBiz is an open source product for the automation of enterprise processes. It includes framework components and business applications for ERP, CRM, E-Business/E-Commerce, Supply Chain Management and Manufacturing Resource Planning. OFBiz provides a foundation and starting point for reliable, secure and scalable enterprise solutions.
Stars: ✭ 83 (-27.83%)
Mutual labels:  web-framework
Flask bestpractices
Flask最佳实践
Stars: ✭ 100 (-13.04%)
Mutual labels:  web-framework
Foal
Elegant and all-inclusive Node.Js web framework based on TypeScript. 🚀.
Stars: ✭ 1,176 (+922.61%)
Mutual labels:  web-framework
Gaea
Gaea is a Gin-based web framework, reference gin https://github.com/gin-gonic/gin
Stars: ✭ 105 (-8.7%)
Mutual labels:  web-framework
Cuba
CUBA Platform is a high level framework for enterprise applications development
Stars: ✭ 1,114 (+868.7%)
Mutual labels:  web-framework
Sincere
Sincere is a micro web framework for Rust(stable) based on hyper and multithreading
Stars: ✭ 91 (-20.87%)
Mutual labels:  web-framework
Totoval
An out-of-the-box artisan API web-framework written in go.
Stars: ✭ 110 (-4.35%)
Mutual labels:  web-framework
Core
🚀 The Node.js Framework highly focused on developer ergonomics, stability and confidence
Stars: ✭ 11,697 (+10071.3%)
Mutual labels:  web-framework
Valval
The fastest web framework in V language (vlang)
Stars: ✭ 103 (-10.43%)
Mutual labels:  web-framework

An object appears at your feet! The voice of Anhur rings out: "Use my gift wisely!" a - an athame named Magicbane.

Hackage Build Status unlicense

magicbane

Magicbane is a Haskell framework for developing ops-friendly, high-performance, RESTful web services.

Okay, that's Dropwizard's tagline. But just like Dropwizard in the Java world, Magicbane combines the best available Haskell libraries to provide a complete web development experience that reduces bikeshedding, wheel reinvention and the number of import lines. Hopefully :)

In particular, Magicbane combines the following libraries:

  • RIO for the Prelude.
  • Servant for REST. It lets you describe web APIs with expressive type system features and implement request handlers with simple functions. Actually somewhat similar to JAX-RS/Jersey, but instead of annotations we have types, because it's Haskell instead of Java. The main feature of Magicbane is an easy way to add stuff (okay, let's call it "modules") on top of Servant.
  • Warp for HTTP.
  • Aeson for JSON.
  • data-has for extending the app context with services (modules). That thing remotely resembles dependency injection. But it's really cool!
  • envy for configuration. Store config in environment variables!
  • fast-logger for logging. Integrated into RIO's logging API, and monad-logger as well for libraries that use it.
  • EKG+monad-metrics for metrics. monad-metrics lets you easily measure things in your application: just use label/counter/distribution/gauge/timed in your handlers. The EKG ecosystem has backends for InfluxDB, Carbon (Graphite), statsd, Prometheus and others… And a simple local web server for development.
  • refined for validation. Why use functions for input validation when you can use types? (You can write things like count ∷ Refined Positive Int in your data type definitions and inputs that don't satisfy the constraints will be rejected when input is processed. Magicbane used to integrate refined with Aeson, but now this is included in refined directly, so it's really just a reexport.)
  • http-client(-tls) for, well, making HTTP requests. Most high level HTTP client libraries are built on top of that. Magicbane provides a small composable interface based on http-conduit, which lets you e.g. stream the response body directly into an HTML parser.
  • http-link-header for the HTTP Link header, unsurprisingly.
  • unliftio for uhhh unlifting.
  • wai-cli for starting Warp. Why write the same stuff in the main function for every new app when you can just use this one. It supports stuff people usually forget to implement there, like UNIX domain sockets, socket activation and graceful shutdown.

Not part of Magicbane, but recommended:

Usage

Here's a hello world service. Just a simple file you can launch with stack script! (Don't use stack script in production though, use proper stack builds, with optimizations and the threaded runtime.)

#!/usr/bin/env stack
{- stack runghc --package magicbane -}
{-# LANGUAGE NoImplicitPrelude, OverloadedStrings, UnicodeSyntax, DataKinds, TypeOperators #-}
import RIO
import Magicbane

type HelloRoute = "hello" :> QueryParam "to" Text :> Get '[PlainText] Text
type ExampleAPI = HelloRoute
exampleAPI = Proxy  Proxy ExampleAPI

hello  Maybe Text  BasicApp Text
hello x = do
  let x' = fromMaybe "anonymous" x
  logInfo $ "Saying hello to " <> display x'
  return $ "Hello " <> x' <> "!"

main = do
  ctx  newBasicContext
  defWaiMain $ magicbaneApp exampleAPI EmptyContext ctx hello

This defines an API that consists of just one endpoint, /hello?to=someone, that does exactly what it says on the tin. Looks like a normal Servant app, but the handler is defined as a BasicApp action. What's that?

That's just an example context for simple apps:

type BasicContext = (ModHttpClient, ModLogger)
type BasicApp α = RIO BasicContext α

Why isn't there Handler / ExceptT mentioned anywhere? Well, it's an antipattern that is now incompatible with http-conduit (needs MonadUnliftIO) and monad-metrics (needs MonadMask). So Magicbane got rid of Servant's ExceptT usage. To return a servantErr, just throwM (throwIO) it.

Anyway, let's make our own context instead of using the basic one:

#!/usr/bin/env stack
{- stack runghc --package magicbane -}
{-# LANGUAGE NoImplicitPrelude, OverloadedStrings, UnicodeSyntax, DataKinds, TypeOperators #-}
import RIO
import Magicbane

type MyAppContext = (ModLogger, ModMetrics)
type MyApp = RIO MyAppContext

type HelloRoute = "hello" :> QueryParam "to" Text :> Get '[PlainText] Text
type ExampleAPI = HelloRoute
exampleAPI = Proxy  Proxy ExampleAPI

hello  Maybe Text  MyApp Text
hello x = timed "hello" $ do
  let x' = fromMaybe "anonymous" x
  logInfo $ "Saying hello to " <> display x'
  return $ "Hello " <> x' <> "!"

main = do
  (_, modLogg)  newLogger (LogStderr defaultBufSize) simpleFormatter
  metrStore  serverMetricStore <$> forkMetricsServer "0.0.0.0" 8800
  modMetr  newMetricsWith metrStore
  let ctx = (modLogg, modMetr)
  defWaiMain $ magicbaneApp exampleAPI EmptyContext ctx hello

Now we have metrics and logging instead of HTTP client and logging! timed is used here to measure how long it takes to say hello.

See the examples directory for more examples.

Development

Use stack to build.

$ stack build

And to run the examples:

$ stack exec runghc examples/larger.hs

Contributing

Please feel free to submit pull requests!

By participating in this project you agree to follow the Contributor Code of Conduct.

License

This is free and unencumbered software released into the public domain.
For more information, please refer to the UNLICENSE file or unlicense.org.

(However, the dependencies are not all unlicense'd!)

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].