Skip to content

funwithcthulhu/contract

Repository files navigation

contract

CI opam license: MIT

contract is an OCaml library for describing HTTP API contracts as typed values. The current code covers a small pure core: endpoint definitions, path matching, scalar and JSON decoding, request and response validation, and OpenAPI output.

Current MVP

The current source tree is a thin vertical slice for REST-style JSON APIs. It has no HTTP server dependency. A request is a value passed to the validator; a response is a status plus optional JSON body checked against the endpoint's declared responses. Path parameters are percent-decoded after route matching.

Released package:

opam install contract

See examples/users_api.ml for a small users API with GET /users/:id and POST /users.

dune exec examples/users_api.exe

Development:

dune build @all
dune runtest
dune fmt

Current limitations:

  • no real HTTP adapter yet
  • no typed client yet
  • no OpenAPI import yet
  • no mock server yet

About

Typed HTTP API contracts for OCaml

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors