package contract

All checked builds pass
  1. Overview
  2. Docs
Typed HTTP API contracts for OCaml

Install

dune-project
 Dependency

Authors

Maintainers

Sources

0.2.0.tar.gz
md5=22bb7430b72c2dd9c141679cc76c0ea5
sha512=d8e8687fd81b1191158ec6d7356887278eb7b7cd60114c4a7f13e52914e9c1ee17eeff37ffa81dd39b4104a553c3e457bacc78907f32ab279130ff5a76b5256f

Description

contract describes REST-style HTTP API contracts as typed OCaml values. The current package provides a pure core for endpoint definitions, parameter and JSON decoding, request and response validation, and OpenAPI 3.0.3 output.

Tags

http api contract openapi

Added to opam-repository:

README

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

Dependencies (3)

  1. yojson >= "2.0.0"
  2. dune >= "3.11"
  3. ocaml >= "5.0"

Dev Dependencies (1)

  1. alcotest with-test & >= "1.9.0"

Optional Dependencies

None

Used by

None

Conflicts

None

Build status

Results of building contract with each compiler on check.ci.ocaml.org, run of against opam-repository 8a77e58. All results for this package.

Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.

Version OCaml 4.11 OCaml 4.14 OCaml 5.2 OCaml 5.4 OCaml 5.5
0.2.0 (this version) n/a n/a good good good
  • good Package successfully built
  • partial One of the dependencies failed to build
  • bad Package failed to build
  • n/a Package is not available in this environment
  • internal Internal failure