-
Notifications
You must be signed in to change notification settings - Fork 813
Creating Api Endpoints
Plugins are able to create their own api endpoints, whether it be for their own consumption, or for the purposes of publishing them to UI developers. This will demonstrate how to build an api endpoint.
Media Browser's api layer is built with Service Stack, so their examples are directly applicable.
Create a class that implements IRestfulService.
You will then have to create request dto classes that describe the request. The following is a complete service example:
`
[Route("/Weather", "GET")]
[Api(Description = "Gets weather information for a given location")]
public class GetWeather : IReturn<WeatherInfo>
{
[ApiMember(Name = "Location", Description = "Us zip / City, State, Country / City, Country", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
public string Location { get; set; }
}
public class WeatherService : IRestfulService
{
public object Get(GetWeather request)
{
var result = Kernel.Instance.WeatherProviders.First().GetWeatherInfoAsync(request.Location, CancellationToken.None).Result;
return result;
}
}
`
WeatherService is the service that processes the request. GetWeather is api method. The route attribute describes the url and http method.
The Api and ApiMember attributes, as well as IReturn are all optional. They only serve to improve documentation.
Emby Home | Latest News | Emby Downloads | Emby Community Forums | © 2019 Emby LLC
- Locating the Server
- Emby Connect
- Browsing the Library
- Latest Items
- Item Information
- Item Types
- Images
- Items by Name
- Web Socket
- Remote Control
- Live TV
- Playlists
- Parental Control
- Filtering
- Sync
- Playback Guidelines
- Audio Streaming
- Video Streaming
- HTTP Live Streaming (HLS)
- Subtitles
- Playback Check-ins