From 9b121acbcfbf476421576211e353230a371af16c Mon Sep 17 00:00:00 2001 From: Maxime Mangel Date: Wed, 15 May 2019 16:49:47 +0200 Subject: [PATCH] Add some docs comments for beta usage --- README.md | 4 ++-- src/Fetch.fs | 60 ++++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 1affa55..838ec24 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -# Thoth.Json [![Build Status](https://dev.azure.com/thoth-org/Thoth.Json/_apis/build/status/thoth-org.Thoth.Json?branchName=master)](https://dev.azure.com/thoth-org/Thoth.Json/_build/latest?definitionId=1&branchName=master) +# Thoth.Fetch [![Build Status](https://dev.azure.com/thoth-org/Thoth.Fetch/_apis/build/status/thoth-org.Thoth.Fetch?branchName=master)](https://dev.azure.com/thoth-org/Thoth.Fetch/_build/latest?definitionId=3&branchName=master) | Stable | Prerelease --- | --- -[![NuGet Badge](https://buildstats.info/nuget/Thoth.Json)](https://www.nuget.org/packages/Thoth.Json/) | [![NuGet Badge](https://buildstats.info/nuget/Thoth.Json?includePreReleases=true)](https://www.nuget.org/packages/Thoth.Json/) +[![NuGet Badge](https://buildstats.info/nuget/Thoth.Fetch)](https://www.nuget.org/packages/Thoth.Fetch/) | [![NuGet Badge](https://buildstats.info/nuget/Thoth.Fetch?includePreReleases=true)](https://www.nuget.org/packages/Thoth.Fetch/) diff --git a/src/Fetch.fs b/src/Fetch.fs index 4c5009e..9fe940a 100644 --- a/src/Fetch.fs +++ b/src/Fetch.fs @@ -17,13 +17,16 @@ type Fetch = /// **Description** /// + /// Retrieves data from the specified resource by applying the provided `decoder`. + /// An exception will be thrown if the decoder failed. + /// /// **Parameters** /// * `url` - parameter of type `string` - URL to be request /// * `decoder` - parameter of type `Decoder<'Response>` - Decoder applied to the server response - /// * `init` - parameter of type `RequestProperties list` - Parameters passed to fetch + /// * `init` - parameter of type `RequestProperties list option` - Parameters passed to fetch /// /// **Output Type** - /// * `JS.Promise<'Response>` - The result of applying the decoder to the server response + /// * `JS.Promise<'Response>` /// /// **Exceptions** /// * `System.Exception` - Contains information explaining why the decoder failed @@ -42,17 +45,22 @@ type Fetch = /// **Description** /// + /// Retrieves data from the specified resource. + /// A decoder will be generated or retrieved from the cache for the `'Response` type. + /// An exception will be thrown if the decoder failed. + /// /// **Parameters** /// * `url` - parameter of type `string` - URL to be request - /// * `init` - parameter of type `RequestProperties list` - Parameters passed to fetch + /// * `init` - parameter of type `RequestProperties list option` - Parameters passed to fetch /// * `isCamelCase` - parameter of type `bool option` - Options passed to Thoth.Json to control JSON keys representation /// * `extra` - parameter of type `ExtraCoders option` - Options passed to Thoth.Json to extends the known coders - /// * `resolver` - parameter of type `ITypeResolver<'Response> option` - Used by Fable to provide generic type info + /// * `responseResolver` - parameter of type `ITypeResolver<'Response> option` - Used by Fable to provide generic type info /// /// **Output Type** - /// * `JS.Promise<'Response>` - The result of applying the decoder to the server response + /// * `JS.Promise<'Response>` /// /// **Exceptions** + /// * `System.Exception` - Contains information explaining why the decoder failed /// static member fetchAs<'Response>(url : string, ?init : RequestProperties list, @@ -62,7 +70,23 @@ type Fetch = let decoder = Decode.Auto.generateDecoderCached<'Response>(?isCamelCase = isCamelCase, ?extra = extra, ?resolver = responseResolver) Fetch.fetchAs(url, decoder, ?init = init) - // Fetch a data structure from specified url and using the decoder + /// **Description** + /// + /// Retrieves data from the specified resource by applying the provided `decoder`. + /// + /// If the decoder succeed, we return `Ok 'Response`. + /// If the decoder failed, we return `Error "explanation..."` + /// + /// **Parameters** + /// * `url` - parameter of type `string` - URL to be request + /// * `decoder` - parameter of type `Decoder<'Response>` - Decoder applied to the server response + /// * `init` - parameter of type `RequestProperties list option` - Parameters passed to fetch + /// + /// **Output Type** + /// * `JS.Promise>` + /// + /// **Exceptions** + /// static member tryFetchAs<'Response>(url : string, decoder : Decoder<'Response>, ?init : RequestProperties list) = @@ -75,6 +99,26 @@ type Fetch = return Decode.fromString decoder body } + /// **Description** + /// + /// Retrieves data from the specified resource. + /// A decoder will be generated or retrieved from the cache for the `'Response` type. + /// + /// If the decoder succeed, we return `Ok 'Response`. + /// If the decoder failed, we return `Error "explanation..."` + /// + /// **Parameters** + /// * `url` - parameter of type `string` - URL to be request + /// * `init` - parameter of type `RequestProperties list option` - Parameters passed to fetch + /// * `isCamelCase` - parameter of type `bool option` - Options passed to Thoth.Json to control JSON keys representation + /// * `extra` - parameter of type `ExtraCoders option` - Options passed to Thoth.Json to extends the known coders + /// * `responseResolver` - parameter of type `ITypeResolver<'Response> option` - Used by Fable to provide generic type info + /// + /// **Output Type** + /// * `JS.Promise>` + /// + /// **Exceptions** + /// static member tryFetchAs<'Response>(url : string, ?init : RequestProperties list, ?isCamelCase : bool, @@ -83,16 +127,19 @@ type Fetch = let decoder = Decode.Auto.generateDecoderCached<'Response>(?isCamelCase = isCamelCase, ?extra = extra, ?resolver = responseResolver) Fetch.tryFetchAs(url, decoder, ?init = init) + /// Alias to `Fetch.fetchAs` static member get<'Response>(url : string, decoder : Decoder<'Response>, ?init : RequestProperties list) = Fetch.fetchAs(url, decoder, ?init = init) + /// Alias to `Fetch.tryFetchAs` static member tryGet<'Response>(url : string, decoder : Decoder<'Response>, ?init : RequestProperties list) = Fetch.tryFetchAs(url, decoder, ?init = init) + /// Alias to `Fetch.fetchAs` static member get<'Response>(url : string, ?init : RequestProperties list, ?isCamelCase : bool, @@ -100,6 +147,7 @@ type Fetch = [] ?responseResolver: ITypeResolver<'Response>) = Fetch.fetchAs(url, ?init = init, ?isCamelCase = isCamelCase, ?extra = extra, ?responseResolver = responseResolver) + /// Alias to `Fetch.tryFetchAs` static member tryGet<'Response>(url : string, ?init : RequestProperties list, ?isCamelCase : bool,