Professional Documents
Culture Documents
RESTful Web Services
RESTful Web Services
Lecture
Version: 1.0-15
RESTful Web Services – Part 2
Mr Shehzad Jaunbuccus
University of Mauritius
Email: s.jaunbuccus@uom.ac.mu
Overview
» Experience scenario
» Client structure
» Server resp
2
RESTful URI design
4
Experience scenario: resources
5
Experience scenario: RESTful URI design
Tips:
List resources in their plural form (e.g., modules instead of
module unlike entities)
The URI should be as simple as possible (user friendly). Do not
allow characters which require URL encoding E.g., spaces in
your URLs. They will have to be encoded with %20 and will be
hard to read. Instead use _ (underscore)or – (hyphen) to
represent spaces in your URLs
6
WS Client: cURL (client URL Request Library)
curl_setopt() Sets the options for the curl session. RESTful web services use http
methods and this function is used to set the type of method a
particular request will use. E.g, CURLOPT_POST will be used for
sending a request through POST.
curl_exec() This function is usually called after curl options have been set and it
allows the request to be sent to the server
8
cURL: main options (used with curl_setopt)
Setting the right curl options is very important since this
will determine the http method used to send the request.
Remember, RESTful URLs do not contain functions name
or the http method name!
cURL function name Description
CURLOPT_URL The location of the resource to process
10
Server processing: basic structure
11
Configuration: mod_rewrite for Apache
mod_rewrite is an Apache module that allows for server-side
manipulation of requested URLs.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ server.php
12
References
13