SaaS CMS has officially launched! Learn more now.

Rejaie
May 10, 2017
  9649
(6 votes)

Episerver CMS + Web API

During my last Episerver project, I needed to stand up a Web API endpoint to grab data from an external source. Sounds easy enough, right? Actually, it is in Episerver. One of Episerver’s greatest strengths is the code base works really well with existing ASP.NET features like Web API. In the scenario above, you can easily wire up a Web API Controller just like you would in any MVC web application. Here are the steps I followed to set up a very simple Web API controller in Episerver:

 

  1. Open your Episerver solution in Visual Studio
  2. Create an API controller named DummyApiController under the Controllers folder. From here, add an action to do something simple, such as returning the number 5.

    Image Step2-1.png

    Image Step2-2.png

  3. Create a code file named WebApiConfig.cs. This fill will contain a method called Register. This method will register the route to our custom API.

    Image Step3-1.png

  4. Add code to register your route with the application in the WebApiConfig.cs file.Image Step4-1.png
  5. Next, call the register method in the Application_Start method. You can find this method in the global.asax.cs fileImage Step5-1.png
  6. Fire up your app, and navigate to your API endpoint (http://host/app-api/getdummynumber). The request will return the number 5!Image Step6-1.png 

 

That’s it. Very, very simple. However, in this case, you will need to do a lot more in terms of security and data input validation. Hope this is helpful to you.

May 10, 2017

Comments

Robert Domingo
Robert Domingo Jan 17, 2018 08:44 PM

how come I couldn't make it work :(

Darren Sunderland
Darren Sunderland Jul 20, 2018 03:23 PM

This works when running on a development machine but when the solution is published to the DXC environment this returns a 404 error everytime.  Is there something further required to get this running in the DXC?

Sam Brooks
Sam Brooks Nov 17, 2020 06:36 PM

thanks Rejaie,

i was struggling to set up an api on an episerver website and this guide was exactly waht i was lookin for. Thanks for keeping it simple, some other examples i found were overly complicated and i was struggling to work out which part i had done wrong.

Sam

Please login to comment.
Latest blogs
Optimizely London Dev Meetup 11th July 2024

On 11th July 2024 in London Niteco and Netcel along with Optimizely ran the London Developer meetup. There was an great agenda of talks that we put...

Scott Reed | Jul 19, 2024

Optimizely release SaaS CMS

Discover the future of content management with Optimizely SaaS CMS. Enjoy seamless updates, reduced costs, and enhanced flexibility for developers...

Andy Blyth | Jul 17, 2024 | Syndicated blog

A day in the life of an Optimizely Developer - London Meetup 2024

Hello and welcome to another instalment of A Day In The Life Of An Optimizely Developer. Last night (11th July 2024) I was excited to have attended...

Graham Carr | Jul 16, 2024

Creating Custom Actors for Optimizely Forms

Optimizely Forms is a powerful tool for creating web forms for various purposes such as registrations, job applications, surveys, etc. By default,...

Nahid | Jul 16, 2024

Optimizely SaaS CMS Concepts and Terminologies

Whether you're a new user of Optimizely CMS or a veteran who have been through the evolution of it, the SaaS CMS is bringing some new concepts and...

Patrick Lam | Jul 15, 2024

How to have a link plugin with extra link id attribute in TinyMce

Introduce Optimizely CMS Editing is using TinyMce for editing rich-text content. We need to use this control a lot in CMS site for kind of WYSWYG...

Binh Nguyen Thi | Jul 13, 2024