Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Adebayo-Adesegun/0bc086050625a1e5f30fbba8a697ca35 to your computer and use it in GitHub Desktop.
Save Adebayo-Adesegun/0bc086050625a1e5f30fbba8a697ca35 to your computer and use it in GitHub Desktop.
Add Deafult Request Headers to GraphQL Queries with HTTP Client
public class ExampleController : Controller
{
private readonly HttpClient _httpClient;
public ExampleController()
{
_httpClient = new HttpClient
{
BaseAddress = new Uri(_urlHelper.GraphQLUri)
};
_httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", "jbkjsbkjbsdkbksbvksdvbjsvb");
}
[HttpPost]
public async Task<IActionResult> Create(ExampleVM model)
{
var query = new {
Query = @"mutation quote($quote: QuoteInput!) {
quote(quote :$quote) {
id,
address,
message,
isActive,
dateCreated,
otherDetails,
brokerId,
brokerSlipPath,
nameOfProspectiveInsured,
isDeleted
}
}",
Variables = new
{
quote = new
{
active = true,
slipFileExtension = ext,
slipBase64 = brokingSlipb64,
message = model.Message,
userId = SignedInDetail.GetUserId(),
quoteId = 0,
status = 1
}
}
};
var json = JsonConvert.SerializeObject(query);
var data = new StringContent(json, Encoding.UTF8, "application/json");
var response = await _httpClient.PostAsync("", data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment