The current ResourceManager is aimed at managing server-side resources. However, the provided RouteSpec could be shared just as other forms of API documentation are shared. The simplest method might be to either pass in an HttpClient instance or have the ResourceManager create and manage its own instance of HttpClient. In either case, it should pass this instance along to the Resource, and the Resource should expose a Send or Request member. The ResourceManager could then double as an HTTP client and server API.
// Create a ResourceManager
let resourceManager = ResourceManager<Resources>()
// Start the manager with the provided spec
use sub = resourceManager.Start(spec)
let responseBody =
async {
// Invoke the ResourceManager as a client
let! response = resourceManager.[Home].[GET]()
// Or with a POST:
//let! response = resourceManager.[Echo].[POST](new MemoryStream())
// Ideally would provide a mapping to expected type rather than raw `System.Net.Http.HttpResponseMessage`.
let! body = Async.AwaitTask <| response.Content.ReadAsStreamAsync()
return body
}
|> Async.RunSynchronously
The current
ResourceManager
is aimed at managing server-side resources. However, the providedRouteSpec
could be shared just as other forms of API documentation are shared. The simplest method might be to either pass in anHttpClient
instance or have theResourceManager
create and manage its own instance ofHttpClient
. In either case, it should pass this instance along to theResource
, and theResource
should expose aSend
orRequest
member. TheResourceManager
could then double as an HTTP client and server API.