Last active
May 28, 2020 17:55
-
-
Save rpjengaard/a80d369f1eff3a266faa to your computer and use it in GitHub Desktop.
How to create a post-method in an UmbracoApiController
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Skybrud.Api | |
{ | |
[JsonOnlyConfiguration] | |
public class TestApiController : UmbracoApiController | |
{ | |
//decorate with HttpPost + use [FromBody] in front of parameter | |
[HttpPost] | |
public object PostSubscriber([FromBody] SubscriberParameters data) | |
{ | |
return Request.CreateResponse<string>(HttpStatusCode.OK, data.Email + ":" + data.Name); | |
} | |
} | |
//because we can´t send multiple parameters, we create a class with the parameters | |
public class SubscriberParameters | |
{ | |
public string Email { get; set; } | |
public string Name { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks.