Try our conversational search powered by Generative AI!

(╯°□°)╯︵ ┻━┻
Mar 18, 2016
  2503
(6 votes)

NuGet: Solita.Episerver.WebApi - WebApi toolkit for Episerver

We, Solita, wish to share our WebApi productivity improvements as a NuGet package, and of course in open source. The source code was released for public in February, but we have used the most of it in production for over a year* with great results. Feel free to implement, contribute and fork :)

NuGet: https://nuget.episerver.com/en/OtherPages/Package/?packageId=Solita.Episerver.WebApi
GitHub: https://github.com/solita/episerver-webapi

What can it do for you?

1. WebApi error logging
By default, Episerver does not log exceptions that happen during WebApi requests. This ExceptionHandler will log the exact URL and the stacktrace. And if you are on the localhost, or an Admin, WebAdmin or WebEditor user, you also get the stacktrace as a result when executing the request to ease debugging, otherwise a plain "An error has occurred" is returned to the caller for security reasons. Here is a log example.

EpiserverWebApiErrorHandler


2. WebApi output caching
Attribute that caches the result for a requested WebApi method. The cache is invalidated when Episerver content changes, so no need to worry about it getting stale. This helps a lot on pages that execute the same XHR request on every load.

EpiserverWebApiOutputCacheAttribute

3. WebApi language context
Attribute that automatically sets the correct language context when the WebApi method is called with a language parameter. After that, you can access the Episerver APIs without explicitly defining the language, just like with PageControllers.

WebApiLanguageAttribute


4. WebApi automatic model validation
Attribute that automatically returns HTTP Bad Request (400) with error details if the model validations fail. No need to do the checks manually in the controller.

ValidateWebApiModelAttribute


5. WebApi StructureMap DependencyResolver
StructureMap DependencyResolver for WebApi to avoid boilerplate code in the project.

Please see the the GitHub page for the latest and more detailed information. We also aim to keep the code as easy to read as possible since it is the documentation :)


* With minor changes the code works with Episerver 8. The latest we have in production is using EPiServer.CMS.Core 9.7.2.

Mar 18, 2016

Comments

Please login to comment.
Latest blogs
Anonymous Tracking Across Devices with Optimizely ODP

An article by Lead Integration Developer, Daniel Copping In this article, I’ll describe how you can use the Optimizely Data Platform (ODP) to...

Daniel Copping | Apr 30, 2024 | Syndicated blog

Optimizely Forms - How to add extra data automatically into submission

Some words about Optimizely Forms Optimizely Forms is a built-in add-on by Optimizely development team that enables to create forms dynamically via...

Binh Nguyen Thi | Apr 29, 2024

Azure AI Language – Extractive Summarisation in Optimizely CMS

In this article, I demonstrate how extractive summarisation, provided by the Azure AI Language platform, can be leveraged to produce a set of summa...

Anil Patel | Apr 26, 2024 | Syndicated blog

Optimizely Unit Testing Using CmsContentScaffolding Package

Introduction Unit tests shouldn't be created just for business logic, but also for the content and rules defined for content creation (available...

MilosR | Apr 26, 2024