Skip to content

frenchan-zz/SimpleClientService

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SimpleClientService

This is a simple client async service that handles GET, POST, PUT, DELETE. Main purpose for building REST service. Data that is used for a request/response is in JSON.

Configure

Register the IClientService on the Startup.cs

services.AddSingleton<IClientService, ClientApiService>();

Appsettings.json requires following properties:

"ClientService": {
    "UserName": "",
    "Password": "",
    "BaseApiUrl": "",
    "Language": "",
    "ApiKey": "",
    "CustomHeaderType": "",
    "CustomHeaderValue": "",
  }

Inject the service in the constructor:

public WeatherService(IClientService clientService, IConfiguration configuration)
{
    _clientService = clientService;
    _configuration = configuration;
}

Sample use of the service:

public async Task<string> GetWeatherForCity(string city)
{
    var uri = new Uri($"{ _configuration["ClientService:BaseApiUrl"] }weather")
         .AddParameter("q", city);

    var result = await _clientService.SimpleExecute(uri, HttpMethod.Get);

    return result.ResponseBody;
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages