Reader small image

You're reading from  Entity Framework Tutorial (Update) - Second Edition

Product typeBook
Published inAug 2015
Reading LevelIntermediate
Publisher
ISBN-139781783550012
Edition2nd Edition
Languages
Right arrow
Author (1)
Joydip Kanjilal
Joydip Kanjilal
author image
Joydip Kanjilal

Joydip Kanjilal is a Microsoft Most Valuable Professional in ASP.NET, as well as a speaker and the author of several books and articles. He received the prestigious MVP (Most Valuable Professional) award at ASP.Net for 2007, 2008, 2009, 2010, 2011, and 2012. He is currently working as a Chief Software Architect at a reputed software company in Hyderabad. Joydip has almost 20 years of industry experience in IT, with more than 14 years in Microsoft .NET and its related technologies. He has been selected as MSDN Featured Developer of the Fortnight (MSDN) and as Community Credit Winner several times. He is the author of several books and more than 250 articles. Many of his articles have been featured at Microsoft's Official Site on ASP.NET. Joydip has authored the following books:- ASP.NET Web API (Packt Publishing) Visual Studio Six in One (Wrox Publishers) ASP.NET 4.0 Programming (Mc-Graw Hill Publishing) Entity Framework Tutorial (Packt Publishing) Pro Sync Framework (APRESS) Sams Teach Yourself ASP.NET Ajax in 24 Hours (Sams Publishing) ASP.NET Data Presentation Controls Essentials (Packt Publishing) Joydip has also reviewed more than a dozen books till date. He was a speaker a speaker at the reputed Spark IT 2010 event and at the reputed Dr. Dobb's Conference 2014 in Bangalore. He's also worked as a judge for the Jolt Awards at Dr. Dobb's Journal. He blogs these days at: http://www.infoworld.com/blog/microsoft-coder
Read more about Joydip Kanjilal

Right arrow

Appendix A. Advanced Concepts

In this chapter we will cover a few advanced concepts. These include: REST and REST-based service frameworks and OData. We would also explore the HTTP methods and the request and response codes. Lastly, we will take a look at the new features in Entity Framework 7.

REST and REST-based service frameworks


Representation State Transfer (commonly known as REST) is an architectural paradigm that is based on the stateless HTTP protocol and is used for designing applications that can intercommunicate. In REST, resources are used to represent state and functionality, and these resources are in turn represented using user-friendly URLs. Note that the REST architecture style can be applied to other protocols as well. The word "stateless" implies the HTTP/HTTPS protocols. The REST architectural style is popular in the HTTP world and gives better results when used in combination with the HTTP protocol.

The key goals of REST include the following:

  • Scalability

  • Compatibility with other technology and platforms

  • Generality of interfaces

  • Discoverability; that is, interconnectivity between resources

  • Components that can be deployed independently of one another

  • Reduced latency

  • Better security

  • Extensibility

A RESTful Web API is a web API that conforms to the REST principles. The main principles of REST include:

  • Identification of resources

  • Stateless communication

  • Manipulation of resources through representations

  • Self-descriptive messages

In this section, we will examine the popular REST-based service frameworks.

Here is the list of the popular REST-based service frameworks or APIs:

  • Ruby on Rails

  • Restlet

  • Django

  • Flickr

  • Google

  • Yahoo

Ruby on Rails

Ruby on Rails is an optimized open source web application framework that runs on top of the Ruby programming language. Ruby on Rails follows the basic software engineering patterns and principles. The Rails Web API is a framework that facilitates the creation of web applications based on the Model-View-Controller (MVC) framework. The view layer is composed of "templates," and most of these templates are HTML-based with embedded Ruby code. The model layer represents the domain model, the business logic classes, and the data access classes. The controller layer handles incoming HTTP requests. Note that the Rails controller can generate XML, JSON, PDFs, and also mobile-specific views. You can get more information on this framework from http://api.rubyonrails.org/.

Restlet

Restlet provides support for an extensive list of extensions that include the following:

  • Spring

  • WADL

  • XML

  • JSON

  • JAX-RS API

The benefits of Restlet include the following:

  • Support for a fully symmetric client and server API

  • Support for connector protocols other than HTTP

  • Support for complete URI routing control through the Restlet API

  • Fast and scalable

  • Powerful filtering support

  • Support for a consistent client and server API

You can explore more on this API from http://restlet.org/discover/features.

Django REST

The Django REST framework provides a powerful and flexible API, using which you can build Web APIs seamlessly. This API provides an extensive documentation and excellent community support. You can know more about this framework from http://django-rest-framework.org/.

The Flickr REST API

The Flickr REST API is simple and easy to use. Flickr also has some JSON APIs that you might make use of for invoking the API through JavaScript. You can get more information about this from http://www.flickr.com/services/api/request.rest.html.

The Google API

The Custom Search JSON/Atom API from Google enables developers to write applications that can leverage this API and retrieve and display custom search in the applications. This API allows you to use RESTful calls for web search and get the results in JSON or Atom format. You can know more on this API from https://developers.google.com/custom-search/json-api/v1/overview.

Note that Google provides a much wider range of API services than APIs, such as Google Maps, AdWords, Translate, Google Analytics, and so on.

Yahoo Social REST APIs

The Yahoo Social REST APIs provide a collection of URI resources that can provide access to the following:

  • Users' profiles

  • Status messages

  • Status updates

These URIs are actually grouped into APIs, depending on the information that they return. For more information, you can refer to http://developer.yahoo.com/social/rest_api_guide/web-services-intro.html.

Exploring OData

The Open Data Protocol (OData) is a protocol that is built on web standards, such as HTTP, Atom, and JSON, and standardizes how data is exposed and consumed. It is a data access protocol that provides a uniform way of performing CRUD operations on the data. It is used to expose and access information from different data sources; that is, relational databases, filesystems, content management systems, and so on.

OData is a standardized protocol that builds on top of core protocols, such as HTTP and architecture paradigms, such as REST. Like RSS, Atom is a way to expose feeds. Note that AtomPub makes use of HTTP verbs such as GET, POST, PUT, and DELETE, to facilitate the publishing of data. OData v4 is now an OASIS standard. It is an open protocol that enables the creation and consumption of queryable and interoperable RESTful APIs.

OData is a REST-based protocol that uses HTTP, JSON, and ATOM, and supports any platform that has support for HTTP, XML, or JSON. You can use it to expose data retrieved from relational databases, filesystems, or data services. OData enables you to perform CRUD operations on top of a data model or a data service. In essence, it is an HTTP-based, platform-independent protocol that supports REST. In OData, data is provided through the usage URIs and common HTTP verbs, such as GET, PUT, POST, MERGE, and DELETE. Note that WCF Data Services (previously known as ADO.NET Data Services) is the implementation of OData Protocol in .NET applications.

The official website of OData Protocol exposes data as an OData Service. The service URL is http://services.odata.org/website/odata.svc.

When you open the page in a browser, this is what the XML markup looks like:

<service xml:base="http://services.odata.org/Website/odata.svc/">
<workspace>
<atom:title>Default</atom:title>
<collection href="ODataConsumers">
<atom:title>ODataConsumers</atom:title>
</collection>
<collection href="ODataProducerApplications">
<atom:title>ODataProducerApplications</atom:title>
</collection>
<collection href="ODataProducerLiveServices">
<atom:title>ODataProducerLiveServices</atom:title>
</collection>
</workspace>
</service>

HTTP methods, request, and response codes


The following table shows the common HTTP methods and their purposes:

Method name

Purpose

DELETE

This is used to delete a resource

GET

This is used to request a specific representation of a resource

HEAD

This is same as GET, but it retrieves only the headers and not the body

OPTIONS

This is used to retrieve the methods supported by the resource

POST

This is used to post or submit data to be processed by the resource

PUT

This is used to create or update data using a particular representation of a resource

The following table shows the HTTP status codes and their purposes:

Status code

Description

100

Informational

200

Successful

201

Created

202

Accepted

300

Redirection

304

Not modified

400

Client error

402

Payment required

404

Not found

405

Method not allowed

500

Server error

501

Not implemented

The following table shows the HTTP redirection status codes:

Status code

Description

300

Multiple choices

301

Moved permanently

302

Found (temporary redirection)

The following table shows the HTTP error status codes:

Status code

Description

400

Bad request

401

Unauthorized

403

Forbidden

404

Resource not found

405

Method not allowed

408

Request timeout

409

Conflict

413

Request entity too large

415

Unsupported media type

The following table shows the HTTP server error status codes:

Status code

Description

500

Internal server error

501

Not implemented

503

Service unavailable

505

HTTP version not supported

The following table lists some resource methods and how they can be implemented using the HTTP protocol:

Method name

Description

HTTP operation

createResource

This creates a new resource

PUT

getResourceRepresentation

This is used to retrieve the representation of a particular resource

GET

deleteResource

This deletes a resource

DELETE

modifyResource

This modifies a resource

POST

getMetaInformation

This retrieves metadata of a resource

HEAD

Abbreviations


  • HTTP: HyperText Transfer Protocol

  • ROA: Resource Oriented Architectures

  • SOA: Service Oriented Architectures

  • SOAP: Simple Object Access Protocol

  • REST: Representational State Transfer

  • RPC: Remote Procedure Call

  • URL: Uniform Resource Locator

  • W3C: World Wide Web Consortium

  • WSDL: Web Service Description Language

  • XML-RPC: XML Remote Procedure Call

New features in Entity Framework 7


Entity Framework 7, a major redesign of the ORM, is the latest version of Entity Framework with the vision of "New Platforms, New Data Stores."

Some of the striking features of this release include support for the following:

  • Non-relational data stores and in-memory data: You can now use Entity Framework with NoSQL databases as well.

    Entity Framework 7 now provides support for the following data providers:

    • SQL Server

    • SQLite

    • Azure Table Storage

    • Redis

    • In Memory (for unit testing)

  • Windows Phone and Windows Store applications, Linux, and Macintosh systems: Entity Framework 7 now provides support for Windows Phone, Windows Store, ASP.NET 5, and desktop applications.

  • Unit testing: Entity Framework 7 now provides support for unit testing your applications against in-memory or memory-resident databases.

You can refer to this Channel 9 video to know more on Entity Framework 7: https://channel9.msdn.com/Events/Build/2015/2-693.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Entity Framework Tutorial (Update) - Second Edition
Published in: Aug 2015Publisher: ISBN-13: 9781783550012
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Joydip Kanjilal

Joydip Kanjilal is a Microsoft Most Valuable Professional in ASP.NET, as well as a speaker and the author of several books and articles. He received the prestigious MVP (Most Valuable Professional) award at ASP.Net for 2007, 2008, 2009, 2010, 2011, and 2012. He is currently working as a Chief Software Architect at a reputed software company in Hyderabad. Joydip has almost 20 years of industry experience in IT, with more than 14 years in Microsoft .NET and its related technologies. He has been selected as MSDN Featured Developer of the Fortnight (MSDN) and as Community Credit Winner several times. He is the author of several books and more than 250 articles. Many of his articles have been featured at Microsoft's Official Site on ASP.NET. Joydip has authored the following books:- ASP.NET Web API (Packt Publishing) Visual Studio Six in One (Wrox Publishers) ASP.NET 4.0 Programming (Mc-Graw Hill Publishing) Entity Framework Tutorial (Packt Publishing) Pro Sync Framework (APRESS) Sams Teach Yourself ASP.NET Ajax in 24 Hours (Sams Publishing) ASP.NET Data Presentation Controls Essentials (Packt Publishing) Joydip has also reviewed more than a dozen books till date. He was a speaker a speaker at the reputed Spark IT 2010 event and at the reputed Dr. Dobb's Conference 2014 in Bangalore. He's also worked as a judge for the Jolt Awards at Dr. Dobb's Journal. He blogs these days at: http://www.infoworld.com/blog/microsoft-coder
Read more about Joydip Kanjilal