This repository was archived by the owner on Feb 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
WebApi Controllers
Dave Greasley edited this page May 30, 2015
·
2 revisions
You can use the model classes as parameters in WebApi controllers like so:
public class BlogCommentApiController : UmbracoApiController
{
[HttpPost]
public bool SubmitBlogComment(BlogComment comment)
{
...
}
[HttpGet]
public List<BlogComment> GetComments(int blogPostId)
{
BlogPost post = new BlogPost(blogPostId);
return post.Children.ToList();
}
}
The models have a blank constructor which allows them to be used with serializers. As such these can be used without any configuration necessary as input parameters and return types in WebApi controllers and they will be serialized / deserialized automatically by the WebApi framework.
Certain properties on the Concrete base class and certain generated properties will be given the [JsonIgnore] attribute automatically. This is normally on IPublishedContent properties as IPublishedContent is quite big and generally you wouldn't want to send all this data to clients of the WebApi.