Beruflich Dokumente
Kultur Dokumente
0
Introduction to the Service APIs
Course materials may not be reproduced in whole or in part without prior written permission of IBM.
Introduction
Need simple, standard way to access REST service data from serverside code
Impractical to force server-side code to make HTTP REST call
REST service data may be stored outside of a database
Support JSON results while allowing for future formats such as XML
Follow current REST coding standards
Standardized exceptions
Avoid calling low-level JDBC code since these implementations vary
greatly
Description
GET
Read
Safe
POST
Create
Unsafe
PUT
Update
DELETE
Safe
Delete
Unsafe
Operation is read-write.
Idempotent
Operation can be repeated without affecting the state of the resource.
Latin for having the same power.
Description
200 (OK)
401 (Unauthorized)
403 (Forbidden)
409 (Conflict)
General Guidelines
Response
A successful POST/PUT request response should include the
new/modified JSON object
Optimistic Concurrency (PUT)
Server compares the resource's current last update timestamp
with the value supplied in the request.
Request processed only if the timestamps match.
Return an HTTP status code of 409 (Conflict) if the timestamps
do not match.
Search (GET)
Searches should be performed by submitting a GET request
along with a query string.
Do not use path parameters for searching. For a complex
search or filter criteria, use query parameters.
Copyright IBM Corp. 2013.
6
General Guidelines
URI Paths
Path parameters should only be used for identifying resources.
Do not use path parameters to add new verbs to the API.
For example, do not use .../{id}/start
Common Properties
id: integer
Uniquely identifies each resource
lastUpdateDate: long
Timestamp value used for concurrency check
Translated Properties
Resource includes the untranslated propert with the translated
property prefixed with i18n
For example: label and i18nLabel
Copyright IBM Corp. 2013.
Design
Web browser
JSON
REST service
Server-side code
POJO
POJO
Data service
POJO
JDBC
Copyright IBM Corp. 2013.
Implementation com.ibm.ioc.rest
REST service
RestResource
Abstract class containing common REST resource methods
All concrete REST resource classes extend this class
RestUtils
Common REST utilities
Exceptions correspond to HTTP response status codes
BadRequestException
400
ConflictException
409
ForbiddenException
403
InternalServerErrorException
500
NotFoundException
404
Implementation com.ibm.ioc.rest
Data service
IDataService
Interface defining the minimum required methods (create, get,
update, delete) and the possible exceptions
DataServiceImpl
Abstract class implementing the IDataService interface
All interface methods implemented as throwing an exception
All concrete data service implementations extend this class and
override the necessary methods
10
Implementation com.ibm.ioc.rest
POJO
IData
Marker interface for all POJOs returned from the data service
DataImpl
Abstract class implementing IData interface
Defines common REST attributes (id, lastUpdateDate, and
messages)
All concrete POJO implementations extend this class
11
12
RestMessage
Defines the data required to display a translated message
messageId: the message ID
messageText: the untranslated message text
i18nMessageText: the translated message text
List<RestMessage> included in DataImpl
Returned with the result of the REST service
ExceptionMessages
Contains List<RestMessage>
Included in any ISSException
13
Displaying Messages
Library functions com.ibm.ioc.Library JavaScript class
publishMessage(messageId, i18nMessageText)
publishRestMessages(result, defaultMessageId,
defaultI18nMessageText)
result: zero or more success messages returned from REST
service
publishRestErrorMessages(error, defaultMessageId,
defaultI18nMessageText)
error: zero or more error messages returned from REST
service
Added features
Determines the correct message type (error, warning, info)
based upon last character of message ID
Automatically adds the current time in the browser's preferred
format
Copyright IBM Corp. 2013.
14
Displaying Messages
IOC Portal themes
Displays messages as an IDX SingleMessage in a scrolling div
15
com.ibm.ioc.sysprop.rs.SyspropResource
Sysprop REST service
Extends RestResource
com.ibm.ioc.sysprop.Sysprop
Sysprop POJO
Extends DataImpl
com.ibm.ioc.sysprop.SyspropDataService
Sysprop REST server-side data service
Extends DataServiceImpl
com.ibm.ioc.sysprop.SyspropJdbcUtils
Sysprop JDBC utilities
Extends JdbcUtils
Copyright IBM Corp. 2013.
16
17
18
data
Questions?
19