What Is Web API: Web API is an open source and ideal platform for building REST-ful services over the .NET Framework. This is the new framework for building HTTP services with easy and simple way. It uses the full features of HTTP (like URIs, request/response headers, caching, versioning, various content formats) It can be hosted with in the application or on IIS.
When to use Web API: when you want to expose your service to a broad range of clients including browsers, mobiles, iphone and tablets or you want to use MediaType Formatter into JSON, XML or whatever format you want to add as a MediaTypeFormatter. It is light weight architecture and good for devices which have limited bandwidth like smart phones.
How Implement Web API in DNN
We need to include few reference of DLL
These dlls are present inside the bin folder in DNN Site.
Now Lets start with some coding
First of all we create a class named TestingWebApiController.cs Let’s see the code that display Email name of current user
One more important thing you should keep in mind the permissions
- [AllowAnonymous] : its sets permission that any user can access this method.
- [DnnAuthorize = " "] : type of dnn user is allowed to access the API
Note: whilst GET and POST are the two most commonly used verbs there are others, particularly if you are looking to use a RESTful approach. Typically a REST based service implementation will use the following verbs:
GET– Used when a browser is requesting data from the server
PUT– Typically used when updating an item
POST – Typically used when creating a new item
DELETE – Used when deleting an item
Now we create Another Class “RouteMapper.cs ” with following code
After That Build the dll of Main Class and post the bin folder in dnn site
Now we can use following path of url
Error! Hyperlink reference not valid.
Get Display data in Json Format
KeyWord:Webapi asp.net,Dnn Web api,C# Web API.
Conclusion: if you want to make your service to a broad range of clients including browsers, mobiles, iphone and tablets,best option is web API.