REST API Client Code Generator

9 views
Skip to first unread message

Carlos Admirador

unread,
Aug 31, 2022, 7:22:05 AMAug 31
to AltNet-Hispano
Recomiendan alguna utilidad para generar código para  un API client REST API ?

https://marketplace.visualstudio.com/items?itemName=ChristianResmaHelle.ApiClientCodeGenerator2022

Carlos Admirador

unread,
Aug 31, 2022, 7:23:16 AMAug 31
to AltNet-Hispano

Carlos Admirador

unread,
Aug 31, 2022, 10:41:58 AMAug 31
to AltNet-Hispano


https://github.com/RicoSuter/NSwag/wiki/NSwagStudio

Parte del código (no sé si con buenas prácticas) que genera:

[System.CodeDom.Compiler.GeneratedCode("NSwag", "13.16.1.0 (NJsonSchema v10.7.2.0 (Newtonsoft.Json v12.0.0.0))")]
public partial class Client
{
private string _baseUrl = "";
private System.Net.Http.HttpClient _httpClient;
private System.Lazy<Newtonsoft.Json.JsonSerializerSettings> _settings;

public Client(string baseUrl, System.Net.Http.HttpClient httpClient)
{
BaseUrl = baseUrl;
_httpClient = httpClient;
_settings = new System.Lazy<Newtonsoft.Json.JsonSerializerSettings>(CreateSerializerSettings);
}

private Newtonsoft.Json.JsonSerializerSettings CreateSerializerSettings()
{
var settings = new Newtonsoft.Json.JsonSerializerSettings();
UpdateJsonSerializerSettings(settings);
return settings;
}

public string BaseUrl
{
get { return _baseUrl; }
set { _baseUrl = value; }
}

protected Newtonsoft.Json.JsonSerializerSettings JsonSerializerSettings { get { return _settings.Value; } }

partial void UpdateJsonSerializerSettings(Newtonsoft.Json.JsonSerializerSettings settings);
partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, string url);
partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, System.Text.StringBuilder urlBuilder);
partial void ProcessResponse(System.Net.Http.HttpClient client, System.Net.Http.HttpResponseMessage response);

/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
public virtual System.Threading.Tasks.Task GetEnvironmentAsync()
{
return GetEnvironmentAsync(System.Threading.CancellationToken.None);
}

Reply all
Reply to author
Forward
0 new messages