fable-fetch
所属分类:collect
开发工具:F#
文件大小:0KB
下载次数:0
上传日期:2022-07-19 02:08:38
上 传 者:
sh-1993
说明: 浏览器获取API的Fable绑定,
(Fable bindings for Browsers Fetch API,)
文件列表:
.config/ (0, 2022-07-18)
.config/dotnet-tools.json (146, 2022-07-18)
Directory.Build.props (1245, 2022-07-18)
Fable.Fetch.sln (1243, 2022-07-18)
LICENSE (1062, 2022-07-18)
RELEASE_NOTES.md (721, 2022-07-18)
build.fsx (203, 2022-07-18)
fable_logo.png (208240, 2022-07-18)
global.json (72, 2022-07-18)
package-lock.json (80435, 2022-07-18)
package.json (486, 2022-07-18)
src/ (0, 2022-07-18)
src/Fable.Fetch.fsproj (761, 2022-07-18)
src/Fetch.fs (22170, 2022-07-18)
tests/ (0, 2022-07-18)
tests/FetchTests.fs (12532, 2022-07-18)
tests/Tests.fsproj (378, 2022-07-18)
tools/ (0, 2022-07-18)
tools/Build.fsproj (476, 2022-07-18)
# Fable.Fetch
Fable bindings for Browsers' [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API).
If you need helpers for automatic JSON serialization, check [Thoth.Fetch](https://github.com/thoth-org/Thoth.Fetch#thothfetch-).
- Run tests: `npm test`
- Publish: `npm run publish` (first bump version in RELEASE_NOTES.md and put your Nuget key in NUGET_KEY env var)
## Usage
```fsharp
type IUser =
abstract name: string
let fetchGitHubUser accessToken =
async {
let! response =
fetch "https://api.github.com/user" [
requestHeaders [
HttpRequestHeaders.Authorization $"token {accessToken}"
] ] |> Async.AwaitPromise
let! item = response.json() |> Async.AwaitPromise
}
```
Response Usage
Normally you don't need to use Response manually but, if you are in a service worker and intercepting fetch requests, you can programatically create responses that satisfy your logic, there are a few javascript runtimes that also offer http frameworks that work with responses directly so here is a few ways to create responses
```fsharp
Response.create("Hello World!", [Status 200; ])
Response.create("Teapot!", [Status 418; Headers [| "x-tea", "green" |] ])
Response.create("Bad Request!", [Status 400; Headers [| "x-custom", "fable" |] ])
Response.create("""{ "message": "Bad Request!" }""", [Status 400; Headers [| "content-type", "application/json" |] ])
Response.create(
Blob.Create([| csvfile |], unbox {| ``type`` = "text/csv" |}),
[ Status 200; Headers ["content-type", "text/csv"] ]
)
```
Check the [tests](https://github.com/fable-compiler/fable-fetch/blob/master/tests/FetchTests.fs) for other examples.
近期下载者:
相关文件:
收藏者: