Skip to content

Simpler route defintion #12

@chrisoldwood

Description

@chrisoldwood

I'm using Hornbill via C# and I've created the following extension method to make routes even simpler to define:

internal static class FakeServiceExtensions
{
    public static void Get(this FakeService service, string path, Func<Request, Response> response)
    {
        service.AddResponse(path, Method.GET, Response.WithDelegate(response));
    }

    public static void Post(this FakeService service, string path, Func<Request, Response> response)
    {
        service.AddResponse(path, Method.POST, Response.WithDelegate(response));
    }
}

This removes some of the ceremony and allows me to write them in a more Nancy like manner:

fakeService.Get("/api/thing/.*", request =>
{
    . . .
    return Response.WithBody(200, ...);
});

What do you think? Do you like the idea of having methods named Get/Put/Post/etc. on the type or would it better to keep them as extensions? Presumably it's possible to define C# style extension methods in F# (or does that not even make sense)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions