In many situations, you might have a need to rewrite HTTP requests and even HTTP responses. For instance, you might have certain parts of your API publically accessible and certain parts that require an API key for access. In this case, you wouldn't want to copy and paste this logic all over your service. ServiceStack supports this in the framework in a number of ways—one way that this author is fond of is using custom attributes. You can use these attributes to inject filters, which will be executed prior to executing a service rendering a response. In this recipe, we'll extend the Reidson Industries Messenger to show how to do that.
First, we'll develop a custom request attribute that verifies that an API key is correct. We'll create it as an attribute and have it extend RequestFilterAttribute
, as follows:
public class ValidateApiKeyAttribute : RequestFilterAttribute { public override void Execute( IRequest req, IResponse...