Answer the question
In order to leave comments, you need to log in
How to test REST API?
Good afternoon, I faced such a problem. It is necessary to check whether everything returns the server to the request correctly.
Let's say we have the following code:
IRestResponse response;
[Test]
public void LoginTest()
{
var client = new RestClient("https://api.site/v1");
var request = new RestRequest("token", Method.POST);
request.AddHeader("content-type", "application/x-www-form-urlencoded");
request.AddParameter("grant_type", "password");
request.AddParameter("username", "[email protected]");
request.AddParameter("password", "qweasd");
response = client.Execute(request);
var result = JsonConvert.DeserializeObject<LoginModel>(response.Content);
}
public class LoginModel
{
public string access_token { get; set; }
public string token_type { get; set; }
public int expires_in { get; set; }
public string userName { get; set; }
public string id { get; set; }
public string roles { get; set; }
public string email { get; set; }
public int routeId { get; set; }
public string firstName { get; set; }
public string lastName { get; set; }
public string emailConfirmed { get; set; }
public string lastSendEmail { get; set; }
public string pathPhoto { get; set; }
public string issued { get; set; }
public string expires { get; set; }
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question