Creating an API for an ASP.NET MVC site with rate-limiting and caching
- by Maxim Z.
Recently, I've been very interested in APIs, specifically in how to create them. For the purpose of this question, let's say that I have created an ASP.NET MVC site that has some data on it; I want to create an API for this site.
I have multiple questions about this:
What type of API should I create? I know that REST and oData APIs are very popular. What are the pros and cons of each, and how do I implement them? From what I understand so far, REST APIs with ASP.NET MVC would just be actions that return JSON instead of Views, and oData APIs are documented here.
How do I handle writing? Reading from both API types is quite simple. However, writing is more complex. With the REST approach, I understand that I can use HTTP POST, but how do I implement authentication? Also, with oData, how does writing work in the first place?
How do I implement basic rate-limiting and caching? From my past experience with APIs, these are very important things, so that the API server isn't overloaded. What's the best way to set these two things up?
Can I get some sample code? Any code that relates to C# and ASP.NET MVC would be appreciated.
Thanks in advance!
While this is a broad question, I think it's not too broad... :)
There are some similar questions to this one that are about APIs, but I haven't found any that directly address the questions I outlined here.