V
V
Valera Figol2017-07-31 16:21:33
C++ / C#
Valera Figol, 2017-07-31 16:21:33

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; }
    }

And you need to check if something has been changed in the API request. What would return all the same fields as in the LoginModel. How can I do that?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lander, 2017-07-31
@usdglander

Postman

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question