Questions tagged [refit]

Refit is a library heavily inspired by Square's Retrofit library, and it turns your REST API into a live interface.

Refit is a .NET library heavily inspired by Square's Retrofit library (JAVA), and it turns your REST API into a live interface. Read more on refit at Github.

204 questions
22
votes
4 answers

Refit.ApiException Error Handling

How do I get to the content of Refit.ApiException? Depending on what the inner content is, I want to let the user know how to proceed. So I see that thrown exception has the following content ... Content…
crazyDiamond
  • 1,070
  • 2
  • 16
  • 20
20
votes
2 answers

Refit Client using a dynamic base address

I am using Refit to call an API using a Typed Client in asp.net core 2.2 which is currently bootstrapped using a single BaseAddress from our configuration Options: services.AddRefitClient() .ConfigureHttpClient(c => { c.BaseAddress =…
sarin
  • 5,227
  • 3
  • 34
  • 63
18
votes
3 answers

Refit and authorization header

Currently, I am adding an authorization header to my request like this: File: SomeFile.cs public interface ITestApi { [Get("/api/test/{id}")] Task GetTest([Header("Authorization")] string authorization, int id); …
thd
  • 2,023
  • 7
  • 31
  • 45
17
votes
3 answers

How to set timeout in Refit library

I am using Refit library in my Xamarin App, I want to set 10 seconds timeout for the request. Is there any way to do this in refit? Interface: interface IDevice { [Get("/app/device/{id}")] Task GetDevice(string id,…
14
votes
3 answers

Refit (C#) - How to download a File

I'm using Refit in my C# application to interact with a REST API, and the API method has a call that returns a .jpg image. I want to download this image using Refit and get it as a byte array, but it seems to return a garbled string. See below. See…
Chris
  • 7,415
  • 21
  • 98
  • 190
12
votes
4 answers

How can I automatically generate refit interfaces from existing Controllers?

I am investigating the refit library and evaluating if I is worth integrating in my project. Let's say I have this Controller that accepts a POST message with a specific contract: [Route("api/[controller]")] [ApiController] public class…
Kzryzstof
  • 7,688
  • 10
  • 61
  • 108
12
votes
2 answers

Multipart Content with refit

I am using multipart with Refit. I try to upload profile picture for my service the code generated from postman is looking like this var client = new RestClient("http://api.example.com/api/users/1"); var request = new…
albilaga
  • 419
  • 1
  • 10
  • 26
10
votes
4 answers

Polly policy not working using "AddPolicyHandler"

I have an application that makes a request for an authenticated service, where it is necessary to pass the access_token. My idea is to use Polly to retry if the access_token is expired. I'm using Refit (v5.1.67) and Polly (v7.2.1) in a .NET Core 3.1…
Marcelo Diniz
  • 161
  • 1
  • 1
  • 8
9
votes
3 answers

Refit - Dynamic AND Static Header

I am using Refit and would like to set both a dynamic AND a static header. For this one specific call I need to set a content-type of application/json (for others, I do not), but I also need to pass a dynamic bearer token. I'm getting a 500 error it…
NullHypothesis
  • 4,286
  • 6
  • 37
  • 79
8
votes
2 answers

"The JSON value could not be converted to Enum in Refit

I have one .Net Core Razor pages app which is trying to call a .Net Core API with a class library created using Refit. I have created one Refit API interface which uses a model with enum as one of the property type. Here is the interface snippet on…
Kishan Vaishnav
  • 2,273
  • 1
  • 17
  • 45
8
votes
3 answers

How to properly post-process Refit return values?

I'm writing some APIs using Refit, which works wonders, and I'm having some trouble figuring out a good (as in "clean", "proper") way to perform some arbitrary processing on the returned data. As an example, consider this code: public interface…
Sergio0694
  • 4,447
  • 3
  • 31
  • 58
8
votes
1 answer

Refit and OAuth authentication in c#, why Http once again

I just found out about the Refit library on GitHub (link: https://github.com/reactiveui/refit) . Besides my first steps in this huge world, I tried to understand why the use of this library comes handy instead of the use of the usual HttpClient when…
Tarta
  • 1,729
  • 1
  • 29
  • 63
7
votes
1 answer

Make Refit supply a parameter in the query string automatically

I'm using Refit to generate a client for a web service. All the URLs of my Web API are like this: https://service.com/api/v3/datasets?api_key=XXXXXXX As you see, the API key is specified in the query string instead of the header. I would like Refit…
SuperJMN
  • 13,110
  • 16
  • 86
  • 185
6
votes
1 answer

Injecting scoped services into DelegatingHandler throws InvalidOperationException

I'm refactoring my code to use Refit for my calls to the WebApi service. The interface is set up and I also created a delegating handler: public class AuthHandler : DelegatingHandler { private readonly TokenProvider tokenProvider; private…
Ivan-Mark Debono
  • 15,500
  • 29
  • 132
  • 263
6
votes
0 answers

How to pass Dictionary as Query parameter in Web API application via Refit and other sources?

I have a little problem with passing Dictionary as part of the parent object as a query parameter. So, I have a method that gets a FormulationParameters variable. public async ValueTask Get([FromQuery] FormulationParameters…
Jane
  • 61
  • 3
1
2 3
13 14