When creating a live API for developers to consume, it's a good idea to protect your API from abuse or misuse by limiting how many times developers can make requests within a specific timeframe. How much this is restricted will depend on a number of factors, including server resources, load generated by a request, and others. In this recipe, we will write a request filter attribute that can be applied to a web-service method to restrict the number of requests in a timeframe a single session can make. This recipe describes a technique that works well for a single server—if your web application has more than one web app server, you'll need to use a distributed cache of some kind, possibly a Redis instance instead of MemoryCache
, which has been used in this recipe.
ServiceStack 4 Cookbook
ServiceStack 4 Cookbook
Overview of this book
Table of Contents (18 chapters)
ServiceStack 4 Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
Configuration and Routing
Services and Data Transfer Objects
Testing and Logging
Object Relational Mapping (OrmLite)
HTML and Form Data
Filters and Validators
Security and Authentication
Working with Redis
Integrating with Other Technologies
Getting Started
Testing Locally
Index
Customer Reviews