Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating REST API for existing MVC based website

Tags:

I have a website developed using ASP.NET MVC3.
I now want to expose a REST API for others to use which will expose the same features as the website.

In the website, once a user has logged in and credentials validated against a DB, the session manages the logged-in state of the user.
How would I do the equivalent with the REST API, where many of the methods exposed require the user to be logged in (or at least have valid username and password)?

In addition to this, would the best approach for the website be to use the REST API also (presuming the API covers all the functionality required by the site)?

How well is ASP.NET MVC3 suited for this - of course taking into account that the site already exists using this framework?

like image 211
user204884 Avatar asked Sep 28 '11 13:09

user204884


People also ask

Can MVC be RESTful?

MVC is restful in nature, but it is not strictly adherent to REST and can be tailored to whatever you see fit.

Can we use Web API with MVC?

Building a Web API Start Visual Studio and select New project from the Start page or from the File menu select "File" -> "New" -> "Project...". In the template pane select Installed Templates and expand the Visual C# menu. Inside that Visual C# select Web. In the list of projects select ASP.Net MVC 4 Web Application.


1 Answers

I wrote up a blog post on how to [Build a RESTful API architecture within an ASP.NET MVC 3 application] years ago and ended up having to let the site go. :( It might be a good start if you want to take on building the REST API into your MVC application.

See answer by @tugberk on using WebAPI for a good solution.

like image 160
Justin Schwartzenberger Avatar answered Oct 24 '22 09:10

Justin Schwartzenberger