Skip to content

Instantly share code, notes, and snippets.

@brianhdk
Created December 12, 2019 07:57
Show Gist options
  • Select an option

  • Save brianhdk/5877fbc2b87d2ffcd7e90a33a436b638 to your computer and use it in GitHub Desktop.

Select an option

Save brianhdk/5877fbc2b87d2ffcd7e90a33a436b638 to your computer and use it in GitHub Desktop.
async Task Main()
{
using (var httpClient = new HttpClient()) // store instance, dispose when your application shuts down
{
httpClient.BaseAddress = new Uri("https://vertica-xmas2019.azurewebsites.net");
var participateRequest = new ParticipateRequest
{
FullName = "",
EmailAddress = "",
SubscribeToNewsletter = true
};
HttpResponseMessage apiResponse = await httpClient.PostAsJsonAsync("/api/participate", participateRequest);
if (!apiResponse.IsSuccessStatusCode) // if the request fails, output the raw response
throw new InvalidOperationException($"{apiResponse.StatusCode}: {(await apiResponse.Content.ReadAsStringAsync())}");
var participateResponse = await apiResponse.Content.ReadAsAsync<ParticipateResponse>();
participateResponse.Dump();
}
}
public class ParticipateRequest
{
public string FullName { get; set; }
public string EmailAddress { get; set; }
public bool SubscribeToNewsletter { get; set; }
}
public class ParticipateResponse
{
public Guid Id { get; set; }
public Credentials Credentials { get; set; }
}
public class Credentials
{
public string Username { get; set; }
public string Password { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment