You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently the router { } CE has no way to allow a HEAD request to be handled. A HEAD request is supposed to return the headers, but not the body, that would have been produced by a GET request. I suggest adding two (well, four) more CE custom operations to the router { } CE:
get_head and get_headf: uses the Giraffe GET_HEAD handler to automatically handle either a GET or HEAD request. According to HTTP HEAD considerations giraffe-fsharp/Giraffe#314, ASP.NET Core already handles the "if it's a HEAD request, do not return a body in the HTTP response" part of the logic, so the extra code in the router for this would be minimal.
head and headf: useful for applications that can cheaply produce the HTTP headers for a resource, but would require expensive work to produce the response body for that resource. This would allow them to skip the expensive work if the client is not actually asking for the response body.
The alternative is to do something kind of ugly like the following:
lethead(handler :string ->HttpHandler)(next :HttpFunc)(ctx :HttpContext)=if HttpMethods.IsHead ctx.Request.Method then
routef "/%s" handler next ctx
else
next ctx
letitemRouter= router {
pipe_through (head ItemController.itemExists)
get "/" ItemController.getAllItems
post "/" ItemController.createItem
getf "/%s" ItemController.getSingleItem
patchf "/%s" ItemController.patchItem
deletef "/%s" ItemController.archiveItem
}letappRoot= router {
forward "/api/items"(itemRouter true)// ...}
(ItemController implementations omitted for brevity and because frankly, they're pretty obvious). Instead of pipe_through (head ItemController.itemExists), I'd like to be able to do headf "/%s" Controller.itemExists in my itemRouter, or else get_headf "/%s" ItemController.getSingleItem if the cost of building the response body for a single item isn't too great.
P.S. Although I've chosen not to use the Saturn controller CE in my application, it would be nice for the controller CE to also grow an exists operation to handle HEAD requests, and to have its show operation default to handling either GET or HEAD requests.
The text was updated successfully, but these errors were encountered:
Currently the
router { }
CE has no way to allow a HEAD request to be handled. A HEAD request is supposed to return the headers, but not the body, that would have been produced by a GET request. I suggest adding two (well, four) more CE custom operations to therouter { }
CE:get_head
andget_headf
: uses the Giraffe GET_HEAD handler to automatically handle either a GET or HEAD request. According to HTTP HEAD considerations giraffe-fsharp/Giraffe#314, ASP.NET Core already handles the "if it's a HEAD request, do not return a body in the HTTP response" part of the logic, so the extra code in the router for this would be minimal.head
andheadf
: useful for applications that can cheaply produce the HTTP headers for a resource, but would require expensive work to produce the response body for that resource. This would allow them to skip the expensive work if the client is not actually asking for the response body.The alternative is to do something kind of ugly like the following:
(ItemController implementations omitted for brevity and because frankly, they're pretty obvious). Instead of
pipe_through (head ItemController.itemExists)
, I'd like to be able to doheadf "/%s" Controller.itemExists
in myitemRouter
, or elseget_headf "/%s" ItemController.getSingleItem
if the cost of building the response body for a single item isn't too great.P.S. Although I've chosen not to use the Saturn
controller
CE in my application, it would be nice for the controller CE to also grow anexists
operation to handle HEAD requests, and to have itsshow
operation default to handling either GET or HEAD requests.The text was updated successfully, but these errors were encountered: