MyNixOS website logo
Description

RFC7807 style response messages.

RFC7807 — Problem Details for HTTP APIs style response messages.

See GitHub README for more information.

Problem Details for HTTP APIs (RFC7807)

Extensible implementation of RFC7807 — Problem Details for HTTP APIs in Haskell.

RFC7807 defines HTTP API error responses that are quite informative. Very basic example of such message could look like:

HTTP/1.1 404 Not Found
Transfer-Encoding: chunked
Date: Sun, 01 Nov 2020 22:28:42 GMT
Server: Warp/3.3.13
Content-Type: application/problem+json;charset=utf-8
Content-Length: 251

{
  "type": "https://example.com/docs/error#upload-to-missing-file",
  "title": "File resource doesn't exist",
  "status": 404,
  "detail": "Cannot upload file content to a non-existent file.",
  "documentId": "ae095978-2f7c-47aa-84dd-220be55195a5"
}

Table of Contents

(Links work on GitHub, but not on Hackage.)

What does this package do?

This library provides a data type Rfc7807Error that represents such error responses. It is designed to be extensible and to allow alternative representation of user defined fields. See module Network.HTTP.RFC7807 for documentation.

In addition the package provides basic support for servant-server package . See Servant.Server.RFC7807 module documentation for more information and usage examples.

Why would I want to use this?

Oh my

There are many ways common ways how API error responses are structured in HTTP APIs. Using this one has few advantages:

  • It is standardised in RFC7807 — Problem Details for HTTP APIs . This can be leveraged in terms of documentation, libraries built with it in mind, and not heaving to reinvent something that people have put a lot of thought into.

  • Gives you a nice template that is still flexible and extensible. This is important if we are retrofitting it into an existing API.

  • Documented by default. The type field is a URL, used correctly can allow us to prevent a lot of issues by linking errors with their documentation.

  • Increasing level of detail. We have type, title, then detail, and finally custom fields. This way we can progressively add more information allowing users to easily debug issues.

  • Proxy friendly. When proxies are involved, so called layering, it is quite easy to loose the original status code. This can also happen with some HTTP libraries that do not retain the status code.

  • Probably more...

There's an interesting article "REST API Error Handling - Problem Details Response by Guy Levin published on 23rd of May, 2018 " that compares various stiles of error responses AKA problem details responses.

When would I want to use something else?

This response structure may not serve your needs if it's clashing with your needs. Some examples of that:

  • Your needs are in direct conflict with the RFC7807 — Problem Details for HTTP APIs standard. For example, fields that are defined by the standard are reserved in your system or protocol you're using.

  • When RFC7807 messages cannot easily be retrofitted into your API and you need to preserve backward compatibility.

  • Probably more...

Usage examples

General usage (not tied to Servant) is documented in module Network.HTTP.RFC7807 in section Usage Examples .

Basic usage with Servant (actually servant-server) is documented in module Servant.Server.RFC7807 in section Usage Examples .

Metadata

Version

0.2.0.0

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows