Skip to content

Instantly share code, notes, and snippets.

@AlphaBs
Created January 17, 2021 06:55
Show Gist options
  • Save AlphaBs/4d8efcb99459869b18635d3c98777a4f to your computer and use it in GitHub Desktop.
Save AlphaBs/4d8efcb99459869b18635d3c98777a4f to your computer and use it in GitHub Desktop.
RestNet
// API Class
public class UserAPI
{
public static EndPoint<User> UploadUserProfile(string id, string message) =>
new EndPoint<User>
{
Path = $"/users/{id}/profile",
Method = "POST",
Queries = new Dictionary<string, string>
{
["responseType"] = "json",
["locale"] = "kr"
},
Body = JsonConvert.SerializeObject(new
{
MessageType = "default",
Message = message
})
};
}
public class Program
{
public static void Main(string[] args)
{
// Create Client
var client = new RestClient()
{
DefaultHost = "http://localhost",
DefaultHeader = new Dictionary<string, string>
{
["Token"] = "usertoken123123",
["Content-Type"] = "application/json"
}
};
// Request 1
var user1 = client.Request(UserAPI.UploadUserProfile("1234", "hello world"));
Console.WriteLine(user1.Name);
// Request 2
var id = "testUser123";
var user2 = client.Request(new EndPoint<User>
{
Path = $"/users/{id}",
Method = "POST",
Body = JsonConvert.SerializeObject(new User())
});
Console.WriteLine(user2.ID);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment