Skip to content

Instantly share code, notes, and snippets.

@ammar-faifi
Created December 6, 2023 17:30
Show Gist options
  • Save ammar-faifi/89022e8b0f8c8888d4fd3d578624d7be to your computer and use it in GitHub Desktop.
Save ammar-faifi/89022e8b0f8c8888d4fd3d578624d7be to your computer and use it in GitHub Desktop.
GraphQL fetch to Petroly
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
await FetchDataFromGraphQL();
}
static async Task FetchDataFromGraphQL()
{
// GraphQL endpoint URL
var endpointUrl = "https://api.petroly.co/";
// GraphQL query
var query = @"
{
search(term: \"202320\", department: \"ICS\", title: \"108\")
}
";
using (var httpClient = new HttpClient())
{
// Set the GraphQL endpoint URL
httpClient.BaseAddress = new Uri(endpointUrl);
// Prepare the GraphQL request
var content = new StringContent($"{{ \"query\": \"{query}\" }}", Encoding.UTF8, "application/json");
// Send the GraphQL request
var response = await httpClient.PostAsync("", content);
// Check for success
if (response.IsSuccessStatusCode)
{
// Read and parse the response content
var responseContent = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseContent);
}
else
{
// Handle errors
Console.WriteLine($"HTTP error: {response.StatusCode}");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment