Detailed Tutorial for Building ASP.Net Web API RESTful Service

2013 年 12 月 25 日4960

When you are designing, implementing, and releasing new REST API a lot of constraints and standards should be considered; once the API is available to public, and clients start consuming it, significant changes are very hard!

There are lot of API designs in the web; but there is no widely adopted design which work for all scenarios, that is why you are left with many choices and grey areas.

So in this multi-part serieswe’ll be building from scratch a sample eLearning system API which follows best practices for building RESTful APIusing Microsoft technology stack. We’ll use Entity framework 6 (Code First) and ASP.Net Web API.

Before digging into code samples and walkthroughI would like to talk little bit about the basics and characteristics of RESTful services and ASP.Net Web API.

Basics of RESTful services:

REST stands forRepresentational State Transfer, it is a simple stateless architecture that runs over HTTP where each unique URL is representation of some resource. There are four basic design principles which should be followed when creating RESTful service:

For more information about RESTful services, you can check this information rich IBM article.

Introducing the ASP.NET Web API

The ASP.Net Web API shipped with ASP.Net MVC4, it has been around more than one year and half. It is considered a framework for building HTTP services which can be consumed by broadrange of clients such as browsers, smart phones, and desktop applications. It is not considered as a part of the MVC framework, it is part of the core ASP.Net platform and can be used in MVC projects, Asp.Net WebForms, or as stand alone web service.

ASP.Net Web API Stack

ASP.Net Web API Stack

Today with the increase of using smart phones and the trend of building Single Page Apps (SPA); having a light weight Web API which exposes your services data to clients is very important. Asp.Net Web API will help you out of the box in creating RESTFul compliantservices using features of HTTP like (URIs, request/response, headers, versioning, and different content formats).

What we’ll build in this multi-part series?

We need to keep things simple and easy to understand and learn from, but at the same time we need to cover different features provided by ASP.Net Web API and best practices to build RESTFul service.

We’ll be building a simple API for eLearning system, this API allows students to enroll in different courses, allows tutors to view students enrolled in each course, do CRUD operations on courses and students, and many more operations. I’ll be listing detailed use cases which we’ll covered in the next post.

We’ll discuss and implement different Web API features such as:

Note: we’ll not build a client in this series, we’ll use Fiddler or PostmanREST client to compose HTTP requests.

I broke down this series into multiple posts which I’ll be posting gradually, posts are:

Different techniques to Implement Versioning – Part 10.

Cashing resources using eTags – Part 11.(Coming Soon)

All the source code for this series is available on GitHub, you can download it locally or you can fork it. If there is nothing clear or ambiguous please drop me a comment and I’ll do my best to reply your questions.

To get the best of this tutorial I recommend you to follow the posts one by one. Happy coding and hopefully this series will help you to get started with ASP.Net Web API

:)

Source codeis available on GitHub.

About these ads

Share this:

Google+

Like this:

Related

This entry was posted in ASP.NET, ASP.Net Web API, CodeProject, Entity Framework, Web API Tutorial and tagged API, ASP.NET, Entity Framework, REST, RESTful, Tutorial, Web API, Web Service on by Taiseer Joudeh.

6 thoughts on “Detailed Tutorial for Building ASP.Net Web API RESTfulService”

    Piusn

    Cool stuff.

    Chad Miller (@FakeChadMiller)

    Many thanks for this tutorial!

      tjoudeh Post author

      You welcome, glad you like it!

    Ronald

    Anybody who likes the to create a serie on building a modern front-end for this tutorial?

      tjoudeh Post author

      I’m designing a SPA using angularJS and bootstrap which will use this API as its backend, keep tuned.

    Gaspard

    This summer (2013), I had to present a dissertation (MSc) involving Near Field Communication (NFC) and your tutorial is almost similar to some features implemented in my dissertation using Java. We used android on the client side (NFC).

Leave a Reply

0 0