Interfaces

Project

Pages Restful

NuGet packageOwin.Framework.Pages.Restful
GitHub sourceOwinFramework.Pages.Restful

Home |  Readme

[Endpoint] attribute | The OWIN Framework Restful

The [Endpoint] Attribute

Attach this attribute to a method to identify it as a web service endpoint. The class containing this method must be decorated with the [IsService] attribute for this to work.

Example Usage

[IsService("order", "/order/", new[] { Method.Post, Method.Get, Method.Put, Method.Delete })]
public class OrderService
{
    [Endpoint(UrlPath = "{id}", Methods = new[] { Method.Get })]
    public void Get(IEndpointRequest request)
    {
        throw new NotImplementedException();
    }
}

The [Endpoint()] attribute has properties that specify how Http requests are routed to the service as folllows.

UrlPath

Specifies the Http path of this endpoint relative to the service BaseUrl property. The endpoint can also specify an absolute path by starting this property value with a forward slash.

If you do not set this property value then the name of the C# method will be used as the relative path.

Methods

For endpoints with an absolute UrlPath this property defines the Http methods that will be routed to this endpoint.

For endpoints with a relative UrlPath this property is a further restriction that is applied after the request is successfully routed to the service. In this case there is no point in adding methods here that are not also in the Methods property of the service.

Analytics

Set this property to define how detailed are the analytics that are measured for this endpoint. You can use intellisense to see the possible values for this property.

RequestDeserializer

Defines the type of deserializer to use when the body of the request is accessed for the first time by the application code.

The deserializer is specified as a class type to use. This class type must implement the IRequestDeserializer interface.

The standard libraries already contain some implementations of IRequestDeserializer that you can take advantage of in your application, but this interface is also straightforward to implement. These classes are in the OwinFramework.Pages.Restful.Serializers namespace.

ResponseSerializer

Set this property to define how objects returned from this endpoint are written to the http response. The default serializer serializes the returned object to Json using the NewtonSoft serializer.

The serializer is specified as a class type to use. This class type must implement the IResponseSerializer interface. There are implementations of this interface in the OwinFramework.Pages.Restful.Serializers namespace.

RequiredPermission

Setting this property means that identities that call this endpoint will have to have this permission assigned to them in the authorization middleware.

Note that this property only has effect if your application includes authorization middleware in the Owin pipeline.

EndpointSpecificPermission

When this property is true the name of the service and method name are passed as the asset name to the authentication check separated by a forward slash. This allows you to define permissions that allow access to service methods using wildcards, for example you can give one group of users permission to call any endpoint in the service whilst other groups of users can only call certain specific endpoints.

ParameterSpecificPermission

This property defines the name of a parameter to the endpoint that will be passed to the authorization check at the asset value. For example you can have an endpoint that updates a users avatar that takes userId as a parameter, then you can set "userId" as the value of the ParameterSpecificPermission, in which case the value of the userId parameter will be passed to the authorization middleware as the asset name, and you can configure the authorization middleware to only grant this permission if the user id is your own user id. You can also define a group of users in the authorization middleware who can call this endpoint for any user id.

ScenarioName

This parameters allows you to define different versions of your service endpoint for different segments of users in A/B testing scenarios. For example one group of users might see data sorted differently or have additional data included in the response so that you can measure the preferences of your usres.