Calling an api method with complex type

  • Thread starter Thread starter Y a h y a
  • Start date Start date
Y

Y a h y a

Guest
Hi

I have an api method as per below at the end. I can call it fine from swagger as per attached screen. How do I make the same call from c#? I am stuck at how to successfully pass complex type.

Thanks

Regards


1615093.png



namespace MyApp.Staff.Api.Controllers
{
[RoutePrefix("v2.0/token")]
public class TokenController : ApiController
{
[HttpPost]
[Route("create", Name = "AdminGetToken")]
public async Task<IHttpActionResult> Get([FromBody]CreateTokenViewModel model)
{

//...


Token token = JsonConvert.DeserializeObject<Token>(jsonContent);
return Ok(token.AccessToken);
}

public class Token
{
[JsonProperty("access_token")]
public string AccessToken { get; set; }

[JsonProperty("token_type")]
public string TokenType { get; set; }

[JsonProperty("expires_in")]
public int ExpiresIn { get; set; }

[JsonProperty("refresh_token")]
public string RefreshToken { get; set; }
}
}
}

namespace MyApp.Staff.Api.Models
{
public class CreateTokenViewModel
{
public string Username { get; set; }

public string Password { get; set; }
}
}

Continue reading...
 
Back
Top