Skip to content

Instantly share code, notes, and snippets.

@rpjengaard
Last active May 28, 2020 17:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rpjengaard/a80d369f1eff3a266faa to your computer and use it in GitHub Desktop.
Save rpjengaard/a80d369f1eff3a266faa to your computer and use it in GitHub Desktop.
How to create a post-method in an UmbracoApiController
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; }
}
}
@buddhika85
Copy link

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment