liveBook · Manning

HTTP method

As explained in Learn Haskell by Example

An HTTP verb is a standardized method token specifying the intended operation of an HTTP request.

An HTTP method is a standardized token that states the intended operation for a request. In Servant, methods become part of an API type: GET can retrieve JSON or return no content, while POST can accept a JSON request body. PATCH and other methods are available for additional endpoint operations. section 17.1.1

Servant combines methods with paths, request data, and response types:

  • GET describes endpoints such as /simple/example and can specify JSON response values. section 17.1.1
  • POST can require a JSON body through ReqBody; Servant rejects requests whose bodies do not match the specification. section 17.1.1
  • PATCH can update a resource identified with Capture, while DELETE and other HTTP methods can also be declared. section 17.1.1
Listing 17.1 A type for the todo list API server
{-# LANGUAGE TypeOperators #-}     #1
{-# LANGUAGE DataKinds #-}        #1
module Todos.Api where

import Servant.API
import Todos.Types

type TodoApi =
  "entries" :> Get '[JSON] [TodoEntry]        #2
    :<|> "add" :> ReqBody '[JSON] TodoEntry :>
 PostCreated '[JSON] Int                       #3
    :<|> "toggle" :> Capture "id" Int :> PatchNoContent    #4

A complete todo API shows GET for listing entries, POST for adding one, and PATCH for toggling an identified entry. section 17.1.1

How Learn Haskell by Example covers it

How deep it goes
Explains method declarations through typed endpoint examples but defers the internals of DataKinds and TypeOperators.
Examples
Uses todo endpoints for listing entries, adding entries, and toggling an identified entry.
What you can do after
Apply it via Servant by declaring typed endpoints for GET, POST, PATCH, and other HTTP methods.
How it connects
Connects HTTP methods to Servant API types, endpoints, request bodies, JSON representations, and API composition.

Also explained in

Compare how 10 books explain HTTP method →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Haskell by Example. The section links point to the parts of the book it draws on.