-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAPIHelper.cs
52 lines (46 loc) · 1.45 KB
/
APIHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using Newtonsoft.Json;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestAutomationAPI
{
public class APIHelper<T>
{
public RestClient restClient;
public RestRequest restRequest;
public string baseUrl = "https://reqres.in/";
public RestClient SetUrl()
{
var restClient = new RestClient(baseUrl);
return restClient;
}
public RestRequest CreatePostRequest(string body, string endPoint)
{
var restRequest = new RestRequest(endPoint, Method.Post);
restRequest.AddHeader("Accept", "application/json");
restRequest.AddParameter("application/json", body, ParameterType.RequestBody);
return restRequest;
}
public RestRequest CreateGetRequest()
{
{
var restRequest = new RestRequest();
restRequest.AddHeader("Accept", "application/json");
return restRequest;
}
}
public RestResponse GetResponse(RestClient client, RestRequest request)
{
return client.Execute(request);
}
public DTO GetContent<DTO>(RestResponse response)
{
var content = response.Content;
DTO dtoObject = JsonConvert.DeserializeObject<DTO>(content);
return dtoObject;
}
}
}