You are using Umbraco therefore use UmbracoWebApi.
Create a controller method that returns your data. In its simplest form, if you want to return all members, you could do this:
using System.Collections.Generic;
using System.Web.Http;
using Umbraco.Core.Models;
using Umbraco.Web.WebApi;
namespace NameOfYourUmbracoWebsiteProject.Controllers.ApiControllers
{
public class MyMemberController : UmbracoApiController
{
[HttpGet]
public IEnumerable<IMember> GetAllmembers()
{
var memberService = ApplicationContext.Services.MemberService;
return memberService.GetAllMembers();
}
}
}
The endpoint url for this method would be:
http://www.mywebsite.com/umbraco/api/MyMember/GetAllMembers
Create the above method and then test the url in a browser (you will see result as xml rather then JSON).
This would return all of your Members (as JSON if called from angular) which is probably not exactly what you want therefore you should probably create a Model that contains the properties for each member that you actually need and then return a collection of that.
For example:
public class MyCustomMember
{
public string Name { get; set; }
public string Email { get; set; }
}
And then change your controller method to return a collection of MyCustomMember
. Again if the endpoint is called from angular, web api should return the collection as JSON
[HttpGet]
public List<MyCustomMember> GetAllmembers()
{
var memberService = ApplicationContext.Services.MemberService;
var listMyCustomMember = new List<MyCustomMember>();
foreach (var member in memberService.GetAllMembers())
{
var myCustomMember = new MyCustomMember
{
Name = member.Name,
Email = member.Email
};
listMyCustomMember.Add(myCustomMember);
}
return listMyCustomMember;
}
Any questions?