Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

(╯°□°)╯︵ ┻━┻
Mar 18, 2016
  2502
(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
Solving the mystery of high memory usage

Sometimes, my work is easy, the problem could be resolved with one look (when I’m lucky enough to look at where it needs to be looked, just like th...

Quan Mai | Apr 22, 2024 | Syndicated blog

Search & Navigation reporting improvements

From version 16.1.0 there are some updates on the statistics pages: Add pagination to search phrase list Allows choosing a custom date range to get...

Phong | Apr 22, 2024

Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog