Home > 2010 Fall DPS913 > Web service that provides School of Computer Studies data

Web service that provides School of Computer Studies data

December 2, 2010 Leave a comment Go to comments

In this post, we introduce a web service that provides a selection of data from the School of Computer Studies.

.

The web service – an introduction

Your professor has created a RESTful web service that provides a selection of data from the School of Computer Studies. This was done to support another course (Web Services Architecture), as well as this iOS programming course, and future app development efforts.

The web service is available at this URI:

http://warp.senecac.on.ca/wsa500_103a03/ws/

Here are a few facts about the service:

  • It will be available at this URI until February 28, 2010 (it may be moved to a different URI at that time)
  • It is a RESTful web service, that serves XML by default
  • JSON is available, if the requestor sets the HTTP accept header to “application/json”
  • There are 54 methods to GET (read) data
  • The web service help page, showing the available methods, is available by appending “help” to the URI
  • At this time, there are no methods that enable the requestor to perform modifications (e.g. PUT, POST, DELETE)

.

The rest of this post will provide more information about the web service.

.

What does the data look like?

The database has about ten (10) tables, loosely organized in three clusters.

There is a cluster that includes tables for the School of Computer Studies programs, and the courses in those programs. The data in these tables is fairly static, and doesn’t change very often. Additionally, in the provided database, the data is incomplete, because it doesn’t (yet) include all courses, and all data about a course.

Another cluster includes tables for the School’s employees (staff and faculty). The data in these tables is fairly static, and doesn’t change very often. All known employees in November 2010 have been included in the database.

The largest cluster includes tables that hold data for state and operations in a semester. For example, which courses are being offered in a specific semester? What is the usage schedule for a specific class/lab room? In a specific course instance, what are the notable dates for tests and assignments? The provided database includes only a sampling of data at the present time, on your professor’s WSA500 and APD601 courses.

The entity diagram that exposes the database as objects is shown below. Click the image to see a full-size view in a new window/tab.

.

Viewing the data

You can use a browser to view the web service’s (data) resources. Here’s how – In a browser’s address bar, enter the URI of the web service resource you want.

Your professor’s opinion is that Internet Explorer is the best browser to use to view RESTful web service resources. In its default configuration, the XML may be displayed in “feed view”; if it is, you can disable feed view ( tba ).

The next-best browser to use is Firefox, however, a few more settings changes are needed for it to easily render the results. Safari isn’t very good at rendering results from this web service, and your professor has little or no experience with Chrome.

As an alternative, your professor has created a “web service viewer” web page that enables you create a request, and view the results as XML or JSON. (The web page also supports PUT, POST, and DELETE operations, but the web service does not.) The web page is available here:

http://warp.senecac.on.ca/wsa500_103a03/

We recommend that you use the web service viewer page when you are working on your iOS app(s). JSON is often the most convenient data format to use in iOS, and the web service viewer will help you easily determine whether the JSON result’s top-level object is an object or a collection.

.

Creating a request in iOS

In our iOS apps so far, we have used a NSURLRequest object to fetch data from a network endpoint. By default, this object is configured as an HTTP GET operation, and includes a header collection that we can’t modify.

Your professor’s web service sends both XML and JSON, but XML by default (i.e. if the accept header is set to */* or its functional equivalent). Therefore, if you want JSON, you will have to modify the accept header.

The solution is to use an NSMutableURLRequest object, which enables you to, among other things, modify the header collection. Anywhere that you would use an NSURLRequest, you can use an NSMutableURLRequest object.

When you have a reference to an NSMutableURLRequest object, you can set the accept header with the following message:

[request setValue:@”application/json” forHTTPHeaderField:@”accept”];

.

NSDictionary, or NSArray?

This is a brief common-sense reminder about handling JSON results.

A JSON result from a web service is materialized in your app as either an NSDictionary, or an NSArray. Which one?

Look at the JSON result. If the first character is a brace ( { ), then assign the result to an NSDictionary.

However, if the first character is a bracket ( [ ), then assign the result to an NSArray.

.


Advertisements
Categories: 2010 Fall DPS913
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: