Overview of FsHttp
master.http files.repository·master·Indexed 19 days ago
https://github.com/fsprojects/fshttpA programmable HTTP client for .NET developers (C#, VB, F#) that provides a readable DSL for common requests and powerful tools for complex HTTP manipulation. It includes a VS Code extension called FsHttp Studio for interactive UI, rich response rendering, and quick metrics.
.http files.FsHttp Studio is a VS Code extension that enhances the FsHttp experience by providing an interactive UI for F# scripts. Key features include:
http { } block in F# scripts.You can find it on the VS Code Marketplace.
To build the project, ensure you have the .NET SDK version specified in ./global.json installed. You can use the F# build script ./build.fsx or the provided bash scripts in the root directory:
./test.sh: Runs all tests. Use --filter Name~'Pattern' to run specific tests../docu.sh: Rebuilds the documentation site../docu-watch.sh: Rebuilds documentation and watches for changes../publish.sh: Publishes all packages (FsHttp and integration packages) to NuGet../test.sh --filter Name~'Response Decompression'FsHttp provides a domain-specific language (DSL) for making HTTP requests in F#. You can use the http computation expression to define requests including the method, URL, headers, and body.
To use it in an F# script (.fsx) or an F# Interactive (FSI) session, include the NuGet package using #r "nuget: FsHttp" and open the FsHttp namespace.
#r "nuget: FsHttp"
open FsHttp
http {
POST "https://reqres.in/api/users"
CacheControl "no-cache"
body
json """
{
"name": "morpheus",
"job": "leader"
}
"""
}In C#, use the Http static class to build requests fluently. Ensure you have the FsHttp NuGet package installed and use await with SendAsync() to execute the request.
#r "nuget: FsHttp"
using FsHttp;
await Http
.Post("https://reqres.in/api/users")
.CacheControl("no-cache")
.Body()
.JsonSerialize(new
{
name = "morpheus",
job = "leader"
})
.SendAsync();To use FsHttp in an F# script (FSI), include the NuGet package using the #r "nuget: FsHttp" directive. You can use the http { ... } DSL to define the method, URL, headers, and body, then pipe the result to Request.send.
#r "nuget: FsHttp"
open FsHttp
http {
POST "https://reqres.in/api/users"
CacheControl "no-cache"
body
jsonSerialize
{|
name = "morpheus"
job = "leader"
|}
}
|> Request.sendFsHttp.Fsi.disableDebugLogs () before making any requests.FsHttp.Fsi.disableDebugLogs ()