All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fsharp-functions-server.Handler.mustache Maven / Gradle / Ivy

There is a newer version: 7.9.0
Show newest version
namespace {{packageName}}

open {{classname}}HandlerParams
open {{classname}}ServiceImplementation
open Microsoft.AspNetCore.Mvc
open Microsoft.AspNetCore.Http
open Newtonsoft.Json
open Microsoft.Azure.WebJobs
open System.IO

module {{classname}}Handlers =

    {{#operations}}
    /// 
    /// {{description}}
    /// 

    {{#operation}}
    //#region {{operationId}}
    /// 
    /// {{summary}}
    /// 
   []
    let {{operationId}}
        ([]
        req:HttpRequest ) =

      {{#hasBodyParam}}
      use reader = StreamReader(req.Body)

      let mediaTypes = [{{#consumes}}"{{mediaType}}";{{/consumes}}] // currently unused

      {{#bodyParam}}
      let bind (contentType:string) body  =
        match (contentType.ToLower()) with
        | "application/json" ->
          body |> JsonConvert.DeserializeObject<{{operationId}}BodyParams>
        | _ -> failwith (sprintf "TODO - ContentType %s not currently supported" contentType)
      {{/bodyParam}}

      let bodyParams = reader.ReadToEnd() |> bind req.ContentType
      let result = {{classname}}Service.{{operationId}} bodyParams
      {{/hasBodyParam}}
      {{^hasBodyParam}}
      let result = {{classname}}Service.{{operationId}} ()
      {{/hasBodyParam}}
      match result with
      {{#responses}}
      | {{operationId}}{{#isDefault}}Default{{/isDefault}}StatusCode{{^isDefault}}{{code}}{{/isDefault}} resolved ->
        {{^primitiveType}}
          let content = JsonConvert.SerializeObject resolved.content
          let responseContentType = "application/json"
        {{/primitiveType}}
        {{#primitiveType}}
          let content = resolved.content
          let responseContentType = "text/plain"
        {{/primitiveType}}
          ContentResult(Content = content, ContentType = responseContentType, StatusCode = System.Nullable({{code}}))
      {{/responses}}

    {{/operation}}
    {{/operations}}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy