How To extend REST services |
This article explains how to extend a Packflow application to handle new REST requests.
Other web services (WCF and SignalR) can be extended in classes representing them.
New methods can be created on these classes to provide new possibilities to consumers.
REST services are working in a different way, requiring a new approach.
Every application project provides a REST handler (PFApplicationRestHandler) class in the "Services" directory.
This will receive all web requests that Packflow is not managing generically and consider should be handled by an application's custom code.
Three types of requests can be customized:
Extended actions made to the item module. Classic item requests follow these formats : "RestItem/APPLICATION_NAME/CONTENTTYPE_NAME/ITEM_ID" or "RestItem/APPLICATION_NAME/CONTENTTYPE_NAME/New".
When more parameters are provided in the URL, it is considered as a custom action.
URLs follow this format: "RestItem/APPLICATION_NAME/CONTENTTYPE_NAME/ITEM_ID/ACTION_NAME/PARAMETER_1/PARAMETER_2/..."
You can override the HandleItemCustomRequest method to handle these requests.
Actions not centered on a specific entity.
This opens REST to custom operations like batch operations, reporting requests, or targeting anything else than Packflow items.
URLs follow this format: "RestCustomAction/APPLICATION_NAME/ACTION_NAME/PARAMETER_1/PARAMETER_2/..."
You can override the HandleCustomActionRequest method to handle these requests.
Requests made on a custom (not Packflow) resource.
URLs follow this format: "RestCustomResource/APPLICATION_NAME/RESOURCE_NAME/PARAMETER_1/PARAMETER_2/..."
You can override the HandleCustomResourceRequest method to handle these requests.
To ease customizations, you can use the following inherited elements:
Please, note that a new instance of the class is created for each request.