Code Monkey home page Code Monkey logo

hedgehog-servant's Introduction

Hedgehog Servant

Hedgehog servant will eat all your servant bugs.

Basic Usage

Define your servant API endpoints and automatically derive request generators for them!

This is accomplished using the genRequest and the heterogeneous list, called GList, that contains all the generators needed for your API.

So, what do we actually need to do?

  1. Define our API (below SimplestApi).
  2. Define generators for each element that gets captured in the request.
  3. Call the function genRequest with a proxy for the API (Proxy @SimplestApi) and all generators needed in a generator list (GList)!

In code this looks like:

-- POST /cats
type SimplestApi =
  "my" :> "cats" :> ReqBody '[JSON] Cat :> Post '[JSON] ()

-- Generate a request to the Cat API from a base URL
catRequestGen :: BaseUrl -> Gen Request
catRequestGen baseUrl =
  genRequest (Proxy @SimplestApi) (genCat :*: GNil) <&>
    \makeReq -> makeReq baseUrl

We construct generator lists with element1 :*: element2 :*: ... elementN :*: GNil, where GNil denotes the end of the generator list. The genRequest function will derive a request from the generators in the list. This includes request bodies, headers and query parameters.

Note: since the generator list may contain many generators for a specific type, the first one will be chosen. This means that for types that may collide (e.g. common types like String,Integer etc), you should define newtype wrappers.

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.