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)?
I'm using Hornbill via C# and I've created the following extension method to make routes even simpler to define:
This removes some of the ceremony and allows me to write them in a more Nancy like manner:
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)?