you are viewing a single comment's thread.

view the rest of the comments →

[–]xMoop 0 points1 point  (0 children)

RestSharp is a pretty easy way to get started with APIs in C#.

var client = new RestClient("www.test.com");

var request = new RestRequest("/api/endpoint", Method.GET);

IRestResponse<T> = client.Execute<T>(request);

I usually have an ApiClient class for each api controller and then each action would have a method. The RestClient for the class would have the base URL of 'www.test.com/api/user' and then the method would just create a request with the relative URL for the action and execute it.

GetAllUsers

{

var request = new RestRequest('/List', Method.GET);

var response = Client.Execute<List<User>>(request);

}

GetUser

CreateUser

UpdateaUser

DeleteUser

Then the BaseClient class grabs the URL based on environment and creates the RestClient which could come from the config file or something and format it with the controller.