Skip to main content

Define endpoints in their own class throughout your code base and have voyager wire them up for you with it's source generator. There is no performance penalty because the work is done during compilation!No interfaces to implement or base classes to inheritfrom. Just write the logic and let voyager write the boilerplate.

[VoyagerEndpoint("weatherForecast/{City}")]
public class WeatherForecastEndpoint
{
public IEnumerable<WeatherForecast> Get(WeatherForecastRequest request)
{
return Enumerable.Range(1, request.Days).Select(index =>
new WeatherForecast(request.City, DateOnly.FromDateTime(DateTime.Now.AddDays(index)), Random.Shared.Next(-20, 55))
);
}
}
Request
public record WeatherForecastRequest([FromRoute]string City, [FromQuery]int Days = 5);
Response
public record WeatherForecast(string City, DateOnly Date, int TemperatureC)
{
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}