REST

peruvianwageslaveInternet and Web Development

Feb 5, 2013 (4 years and 6 months ago)

137 views

ADVANTAGE
WEBAPI

PETER FUNK

SOFTWARE ENGINEER, ADVANTAGE
R&D

MAY 20, 2011

2



Advantage Technical Summit


May 2011

AGENDA


Introduction


REST


Framework


Security


Authentication


Database specific


Client development pattern

3



Advantage Technical Summit


May 2011

4



Advantage Technical Summit


May 2011

INTRODUCTION


ADS
WebAPI

implements a
RESTful

web service


Accessible from any client that can implement HTTP web
requests


Requirements of a client’s library (PUT, GET, POST, DELETE), SSL,
basic authentication


Data dictionary


ADS 10.10 (latest EBF, work in progress)

5



Advantage Technical Summit


May 2011

REST


Representational State Transfer (
ReST
)


Client and server architecture, stateless


Client transitions from states or at “rest” when idle


Transitions during requests


Interacts with user while at rest


Uses links (URIs) to initiate a new state transition


Each request contains all information to service the request


Methods GET (SELECT), PUT (UPDATE), POST (INSERT), DELETE
(DELETE)


Recommended reading:
RESTful

Web Services

by Leonard
Richardson and Sam Ruby

6



Advantage Technical Summit


May 2011

FRAMEWORK


oData



Open Data Protocol (odata.org)


Web protocol for querying and updating data


Built on top of HTTP,
AtomPub
, and JSON


AtomPub

(Atom Publishing Protocol)


XML


JSON


JavaScript Object Notation (json.org)


Lightweight data
-
interchange format


Easy to read, parse, and generate

7



Advantage Technical Summit


May 2011

EXAMPLE XML

<?xml version="1.0" encoding="iso
-
8859
-
1" standalone="yes"?>

<feed
xml:base
="http://server/adsweb"
xmlns:d
="http://schemas.microsoft.com/ado/2007/08/dataservices"
mlns:m
="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns
="http://www.w3.org/2005/Atom">


<title type="text">demo10</title>


<id>http://server/adsweb/exampledb/v1/tables/demo10</id>


<updated></updated>


<link
rel
="self" title="demo10"
href
="demo10" />


<entry>


<id>http://server/adsweb/exampledb/v1/tables/demo10(5)</id>


<title type="text"></title>


<updated></updated>


<author>


<name />


</author>


<link
rel
="edit" title="demo10"
href
="http://server/adsweb/exampledb/v1/tables/demo10(5)" />


<category term="Model.demo10" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />


<content type="application/xml">


<m:properties>


<d:DEPTNUM m:type="Edm.Int16">18</d:DEPTNUM>


<d:LASTNAME m:type="
Edm.String
">Costello</d:LASTNAME>


<d:FIRSTNAME m:type="
Edm.String
">Angie</d:FIRSTNAME>


<d:DOH m:type="
Edm.DateTime
">1989
-
07
-
16T00:00:00</d:DOH>


<d:SALARIED m:type="
Edm.Boolean
">true</d:SALARIED>


<d:EMPID m:type="Edm.Int32">5</d:EMPID>


<d:PHONE m:type="
Edm.String
">381
-
8410</d:PHONE>


<d:DOB m:type="
Edm.DateTime
">1948
-
04
-
19T00:00:00</d:DOB>


<d:EXTENSION m:type="Edm.Int16">7066</d:EXTENSION>


<d:SOC_SEC_NU m:type="
Edm.String
">538
-
62
-
6755</d:SOC_SEC_NU>


<d:MARRIED m:type="
Edm.Boolean
">true</d:MARRIED>


<d:DIVISION m:type="
Edm.String
">Production</d:DIVISION>


<d:BRANCH m:type="
Edm.String
">Los Angeles</d:BRANCH>


</m:properties>


</content>


</entry>

</feed>

http://server/adsweb/exampledb/v1/tables/demo10(5)

8



Advantage Technical Summit


May 2011

EXAMPLE JSON

{


"d": {


"results": [


{


"__metadata": {


"
uri
": "http://server/adsweb/exampledb/v1/tables/demo10(5)",


"
key_fields
": "EMPID",


"
rows_affected
": 0,


"
last_autoinc
": 0


},


"DEPTNUM": 18,


"LASTNAME": "Costello",


"FIRSTNAME": "Angie",


"DOH": "1989
-
07
-
16T00:00:00",


"SALARIED": true,


"EMPID": 5,


"PHONE": "381
-
8410",


"DOB": "1948
-
04
-
19T00:00:00",


"EXTENSION": 7066,


"SOC_SEC_NU": "538
-
62
-
6755",


"MARRIED": true,


"DIVISION": "Production",


"BRANCH": "Los Angeles"


}


]


}

}

http://server/adsweb/exampledb/v1/tables/demo10(5)?$format=json

9



Advantage Technical Summit


May 2011

APACHE MODULE


WebAPI

is an Apache module that communicates with ADS


Security updates to Apache, not ADS


Configurable with
ads.conf


Authentication


SSL


Expose your database


Connection strings

10



Advantage Technical Summit


May 2011

SECURITY


Outward security handled by Apache


Keep Apache up to date


Web server & database server on separate machines


Require SSL (Secure Sockets Layer)


Encryption


Certificate


Self signed for testing


Official for production

11



Advantage Technical Summit


May 2011

AUTHENTICATION


DbAuthentication


“None”: No authentication required. Note if Apache is not prompting for
authentication, you will very likely want to only expose this data as a read
-
only
feed. To accomplish this, set up a database user with read
-
only privileges, and
specify that username and password in your
DbConnection

string. It would be a
great idea to test this setup by trying to perform an update as well.



“Database” (default): User credentials will be prompted for, and routed to
Advantage for verification via existing user accounts in the database.



“Apache”: Used if you would rather use an Apache module for authentication. If
specified, you must then provide Apache directives for your specific module. For
example, you could use the
AuthBasicProvider

and
AuthUserFile

directives to
implement authentication via an Apache
passwd

file. Note if you use “Apache”
authentication you must then provide a database username and password in
your
DbConnection

string.

12



Advantage Technical Summit


May 2011

DATABASE SPECIFIC


Conflicts


Rowversion
,
modtime


Stored procedures and triggers


Transactions on server
-
side only or with batch updates


Primary keys


Non
-
nullable

fields


Data Dictionary


Binary data is base64 encoded/decoded


QURTIFJ1bGVzIEJhYnkh

13



Advantage Technical Summit


May 2011

DEVELOPMENT PATTERN


HTTP request


XML or JSON deserialization


Proxy classes


Look for client libraries that can make these easy for you



Utilities


LINQPad


Fiddler


Chrome Browser


Curl

14



Advantage Technical Summit


May 2011

FUTURES


oData

specification evolving


Delta links provide updates to data stored locally on the
client


Apache packaged with ADS install


Apache updates with ADS updates (EBFs)

15



Advantage Technical Summit


May 2011

GETTING STARTED


Advantage Web API blog post


http://jdmullin.blogspot.com/2010/09/advantage
-
web
-
api.html


Web API Quick Start Guide


https://docs.google.com/document/d/1dQsxVf8K0t4HmHvNoaAgx2c_UTDnoo1cTVNHvAjtD78/edit?hl=en&authkey=CNCJj44B


Beta user signup


http://www.surveymonkey.com/s/D3R6NGS


User group forums


news://DevZone.AdvantageDatabase.com/advantage.webapi


All things
oData


http://www.odata.org


http://www.odata.org/developers/odata
-
sdk


Client libraries


.NET JSON.NET
http://james.newtonking.com/pages/json
-
net.aspx


Java
Restlet

http://www.restlet.org/


Ruby
ruby_odata

https://github.com/visoft/ruby_odata


iOS

Objective
-
C
http://odataobjc.codeplex.com/

16



Advantage Technical Summit


May 2011

VIDEOS


Consuming
oData

from .NET (and other MS environments)


http://msdn.microsoft.com/en
-
us/data/video/gg591296