String formatting for URL segments
First I wanted to say, this is a great time-saver library. Thank you. I ❤ Refit.
Is your feature request related to a problem? Please describe.
I need to send a GET query to an endpoint with a GUID including curly braces like /api/orders/123/files/{01cdce89-9ba8-450b-96fa-4faf97eee4c0} and I'm using a complex object as a request parameter.
My method looks like this:
[Get("/api/orders/{request.OrderId}/files/{request.FileId}")]
Task<IApiResponse<string>> GetFileUrl(GetFileUrlRequest request);
My main problem is, I can't add curly braces in URL segment.
Describe the solution you'd like
-
First solution could be using escape characters for
{and}, so I could write my attribute like this[Get(@"/api/orders/{request.OrderId}/clientfiles/\{{request.FileId}\}")]For now it's not supported (I suppose) -
Second solution, like
[Query (Format = "something")], I would like to be able to format URL segments[Segment (Format = "something")]For now it's not supported (I suppose)
Describe suggestions on how to achieve the feature For now I've modified my request POCO like this:
public class GetFileUrlRequest
{
[JsonIgnore]
public int OrderId { get; set; }
[JsonIgnore]
public Guid FileId { private get; set; }
[JsonIgnore]
public string FileIdWithCurlyBraces => $"{FileId:B}";
}
And my get attribute looks like [Get("/api/orders/{request.OrderId}/files/{request.FileIdWithCurlyBraces}")]
I don't like this method because of two reasons:
-
First reason: I have to add
private gettoFileIdproperty, otherwise it's adding this property to the end of the query as a query parameter like this:/api/orders/123/files/{01cdce89-9ba8-450b-96fa-4faf97eee4c0}?FileId=01cdce89-9ba8-450b-96fa-4faf97eee4c0}. Maybe Refit has some another attribute to ignore a field without using aprivate setbut I couldn't find. -
Second reason: I need to add another field like
FileIdWithCurlyBracesfor this to achieve simple formatting.
Best, Mustafa
URL encode the desired { and } into %7B and %7D
[Get("/api/orders/{request.OrderId}/files/%7B{request.FileId}%7D")]