2,782 questions
Well if you had an API with an endpoint like this (a .NET 6.0 Microsoft.NET.Sdk.Web project):
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapPost("/api/Authentication/Authenticate", (AuthDetails details) => {
return "token_123";
});
app.Run();
class AuthDetails {
public string Username { get; set; }
public string Password { get; set; }
}
Then you could call it like this (a .NET 6.0 Microsoft.NET.Sdk project):
using Refit;
var authApi = RestService.For<IAuthApi>("https://localhost:7286");
var token = await authApi.GetToken(new AuthDetails { Username = "Paul", Password = "gimme_a_token" });
Console.WriteLine(token);
Console.ReadLine();
public class AuthDetails {
public string Username { get; set; }
public string Password { get; set; }
}
public interface IAuthApi {
[Post("/api/Authentication/Authenticate")]
Task<string> GetToken(AuthDetails details);
}
I suppose it makes sense if you have these AuthDetails
request/response types you could put them in a separate project and share them between the projects.