http-api-data

Converting to/from HTTP API data like URL pieces, headers and query parameters.

http://github.com/fizruk/http-api-data

Version on this page:0.5.1
LTS Haskell 22.39:0.5.1
Stackage Nightly 2024-10-31:0.6.1@rev:1
Latest on Hackage:0.6.1@rev:1

See all snapshots http-api-data appears in

BSD-3-Clause licensed and maintained by Nickolay Kudasov
This version can be pinned in stack with:http-api-data-0.5.1@sha256:31d945aebe9839d005f91703af9df5bd1efe5377060c950f9ec637f84c73a2a5,3519

Module documentation for 0.5.1

http-api-data

Build Status Hackage package Stackage LTS Stackage Nightly

This package defines typeclasses used for converting Haskell data types to and from HTTP API data.

Examples

Booleans:

>>> toUrlPiece True
"true"
>>> parseUrlPiece "false" :: Either Text Bool
Right False
>>> parseUrlPieces ["true", "false", "undefined"] :: Either Text [Bool]
Left "could not parse: `undefined'"

Numbers:

>>> toQueryParam 45.2
"45.2"
>>> parseQueryParam "452" :: Either Text Int
Right 452
>>> toQueryParams [1..5]
["1","2","3","4","5"]
>>> parseQueryParams ["127", "255"] :: Either Text [Int8]
Left "out of bounds: `255' (should be between -128 and 127)"

Strings:

>>> toHeader "hello"
"hello"
>>> parseHeader "world" :: Either Text String
Right "world"

Calendar day:

>>> toQueryParam (fromGregorian 2015 10 03)
"2015-10-03"
>>> toGregorian <$> parseQueryParam "2016-12-01"
Right (2016,12,1)

Contributing

Contributions and bug reports are welcome!

Changes

0.5.1

  • Add toEncodedQueryParam to ToHttpApiData type class. It has default implementation using toQueryParam, but may be overriden with more efficient one.

0.5

  • Use attoparsec-iso8601-1.1.0.0. Day and UTCTime parsers require at least 4 digits now, which is a breaking change.
  • Drop GHC-7.8 and GHC-7.10 support.

0.4.3

  • Add Quarter, QuarterOfYear and Month instances
  • Support bytestring-0.11

0.4.2

  • Add instances for Const and Identity

0.4.1.1

  • Allow cookie <0.5
  • Change to build-type: Simple

0.4.1

  • Use time-compat to provide instances for DayOfWeek.

0.4

  • NominalDiffTime instances preserve precision (roundtrip)
  • Add Semigroup.Min, Max, First, Last instances
  • Add Tagged b a instances

0.3.10

  • Fix ‘SetCookie’ instances (see #86)
  • Add support for Fixed (see #78)

0.3.9

  • GHC-8.6 support
  • Remove dependency on uri-bytestring and use functions from http-types instead (see #75)
  • Add support for SetCookie (see #74)

0.3.8.1

  • GHC-8.4.1 support

0.3.8

  • Minor changes:
    • Stable URL-encoding for Forms (see #67):
      • Introduce urlEncodeParams and urlDecodeParams;
      • Introduce urlEncodeAsFormStable and use stable encoding for doctests;
      • Add toEntriesByKeyStable and toListStable;
    • Add Semigroup instance for Form (see #69);
    • Relax upper bound on Cabal (see #73).

0.3.7.2

  • Allow http-types-0.12
  • .cabal file adjustments

0.3.7.1

  • GHC-8.2 support (see #55).

0.3.7

  • Minor changes:
    • Use attoparsec-iso8601 for parsing of time types. Now the accepted formats are the same as by aeson, i.e. parsers are more lenient (see #41);
    • Preserve fractions of a second in ToHttpApiData instances (see #53);
    • Add ToHttpApiData and FromHttpApiData instances for TimeOfDay (see #53).

0.3.6

  • Minor change:
    • Add toEncodedUrlPiece class method for URL-encoded path segments (see #50); use efficient encoding for types whose values don’t need URL-encoding.

0.3.5

  • Minor changes:
    • Add LenientData which always succeeds to parse (see #45).

0.3.4

  • Minor changes:
    • Add support for GHC 8.2, drop support for GHC 7.6 (see #44).

0.3.3

  • Minor changes:
    • Expose Form constructor from Web.FromUrlEncoded (see #40);
    • Fix example in FromForm documentation (see #39).

0.3.2

  • Minor change:
    • Export Form type from Web.FormUrlEncoded (see #37).

0.3.1

  • Minor changes:
    • Add instances for Data.UUID (see #34).

0.3

  • Major changes:

    • Add Web.FormUrlEncoded to work with form data (see #32).
  • Minor changes:

    • Add instances for Numeric.Natural (see d944721).

0.2.4

  • Make parseHeader total (instead of throwing exceptions on invalid Unicode, see #30).

0.2.3

  • Add more parser helpers for Bounded Enum types.

0.2.2

  • Add instances for more time types: LocalTime, ZonedTime, UTCTime and NominalDiffTime

0.2.1

  • Add helpers for multiple URL pieces and query params:
    • toUrlPieces, parseUrlPieces
    • toQueryParams, parseQueryParams

0.2

  • Export helper functions from Web.HttpApiData:
    • parseUrlPieceMaybe, parseHeaderMaybe, parseQueryParamMaybe
    • parseUrlPieceWithPrefix, parseHeaderWithPrefix, parseQueryParamWithPrefix
    • showTextData, readTextData, parseBoundedTextData
  • Fix AMP related warnings

0.1.1

  • Add use-text-show flag to optionally use more efficient TextShow instances