Search code examples
c#.net.net-coreparametersrefit

How to pass path params using command in REFIT .NET


This is my refit interface

public interface IRefitInterface
{

    [Get("/v1/report/student-statement")]
    Task<GetStudentRecordResponse> GetStudentsRecordsAsync(
        GetStudentRecordCommand command,
        CancellationToken cancellationToken = default);
}

This is how my command looks like :

public sealed class GetStudentRecordCommand
{
    public GetStudentRecordCommand(string id)
    {
        Id = id;
    }
    [AliasAs("id")]
    public string Id { get; private set; } = string.Empty;
}

I want to send this id in path parameters like this :

[Get("/v1/report/student-statement/{id}")]

But I don't want to add it in command parameters due to some constraint's, I want to handle it in command.

I achieved similar thing for query params like this :

public sealed class GetStudentRecordCommand
{
    public GetStudentRecordCommand(string id)
    {
        Id = id;
    }
    
    [Query]
    [AliasAs("id")]
    public string Id { get; private set; } = string.Empty;
}

But unable to achieve it for path params ?

How can I achieve it ?


Solution

  • This one worked :

    [Get("/v1/report/student-statement/{command.Id}")]