Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customizing service handlers #1357

Open
granicz opened this issue Oct 18, 2023 · 0 comments
Open

Customizing service handlers #1357

granicz opened this issue Oct 18, 2023 · 0 comments

Comments

@granicz
Copy link
Member

granicz commented Oct 18, 2023

Given a record or class-based IApi definition, one usually injects it into the server's routes via:

type IApi = {
    [<Rpc>]
    GetAllUsers : unit -> Async<DTO.User list>
}

let server : IApi = {
    GetAllUsers = fun () -> ...
    }
}

WebSharper.Core.Remoting.AddHandler typeof<IApi> server

This underneath the cover creates paths like /IApi/*, but the client is shielded from having to know the details and instead can just call using the established interface:

let server = Remote<IApi>
let doSomething() = 
    async {
        let! hello = server.GetAllUsers()
        printfn $"{hello}"
    }
    |> Async.StartImmediate

However, it would be beneficial to be able to customize how the various RPCs in the supplied service record/class are exposed.

Proposal: allow [<EndPoint>] on the RPC type to override the URL prefix for the service group (so changing /IApi/* to /api/*):

[<EndPoint "/api">]
type IApi = { ... }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant