l12: rest service

38
1 i-views University Part 12: REST Service

Upload: medialeg-gmbh

Post on 14-Apr-2017

14 views

Category:

Data & Analytics


1 download

TRANSCRIPT

Page 1: L12: REST Service

1

i-viewsUniversityPart12:RESTService

Page 2: L12: REST Service

22

REST-Service

PatrickCloshen

SoftwareEngineer

intelligentviews gmbh

Today‘s Speaker

Page 3: L12: REST Service

33

REST-Service

Agenda

1. Introduction

2. Set-up issues

3. Configuring services

4. Homework

Page 4: L12: REST Service

44

REST-Service

1.Introduction

• Accessand edit the semantic graph database viaREST-Services

• Specify what can be seen and how it is displayed and edited viaview configurations

• Make use of pre-defined resources

• Compose the back-endpart for your own web-frontends

Page 5: L12: REST Service

55

REST-Service

Architecture

mediator

Web-frontend

http/https

REST-bridges

internal/http

Page 6: L12: REST Service

66

REST-Service

2.Set-up issues

• RESTcomponent:provides needed schema for services and resources• Needsto be added inthe Admin-Tool

• Configuration of front-ends:front-ends need to be connected to the bridges to render the served data

• Additionalsettings:your semantic graph database musthave auser typethat provides apasswordattribute.Thiswillbe set up if you choose auser typewithin the settings inthe knowledge builder,tab„system“,item„rights“(needed for authentication)

Page 7: L12: REST Service

77

REST-Service

Set-up issues

• Configuration of REST-bridges:configuration file bridge.ini is needed to specify which services aregoing to be provided by the application

• Define the host[and port]of the server of the semantic graph database

• Define the name of the volume to be accessed

• Define the port over which the services willbe available

• Define the services this instance of REST-bridgeis going to serve

Page 8: L12: REST Service

88

REST-Service

3.Configuring services

• Theinstallation of the RESTcomponent inthe semantic graph database provides schema for serviceand resource objects and installs the built-inresources

• Services• They bundle resources to differentiate between differentsets of capabilities as needed

• They need to be identified inthe configuration of the bridge(s)to be available

• Resources• They define what requests are available within the containing service (path)and how they are executed

• They define which HTTP-Method is used

• They declare whether to use authentication or not

• They define the parametrization of the request

Page 9: L12: REST Service

99

REST-Service

TheRESTservice description

Listof RESTservices

Servicedetails

Page 10: L12: REST Service

1010

REST-Service

Buildingblocks (RESTservice)

- Collectionof resources- Startof the URLpath- Servicesare configured inthe

bridge.ini

[Default]host=localhostloglevel=10

[KHTTPRestBridge]volume=Schulungsnetzport=8815services=music

Page 11: L12: REST Service

1111

REST-Service

Buildingblocks (RESTresource)

- Remainder of the URL-path- MultipleTypes

- Scriptresource- Built-inresource- Static resource

- Defines apath-pattern- Partsin{curlyBrackets}are

placeholders for variables

Page 12: L12: REST Service

1212

REST-Service

Buildingblocks (RESTmethod,script resources only)

HTTPmethod- GET,POST,PUT,DELETE…

Input/Outputmedia type- mime-types of accepted and

produced data

Script- JavaScriptthat is executed to

compute the response

Transaction- Read,Write,Controlled by

script

Page 13: L12: REST Service

1313

REST-Service

Buildingblocks (RESTparameter)

Location(Style)- Path-variables- Query-parameters- HTTPheaders

Datatypes coercion- String,Integeretc.- Specialk:element

Repeating- ?album=abc&album=cde

Fixedvalue- default if parameter is absent

Required- Error,if parameter is absent

Page 14: L12: REST Service

1414

REST-Service

Buildingaresource (Addaresource)

Theleft button always adds anewconfiguration object

Page 15: L12: REST Service

1515

REST-Service

Buildingascript resource (Addamethod)

Theleft button always adds anewconfiguration object

Page 16: L12: REST Service

1616

REST-Service

Buildingascript resource (Selectamedia type)

Theleft button always adds anewconfiguration object

Page 17: L12: REST Service

1717

REST-Service

Buildingascript resource (Selectamedia type)

Theleft button always adds anewconfiguration object

Page 18: L12: REST Service

1818

REST-Service

Buildingascript resource (Createanew JavaScript)

Theleft button always adds anewconfiguration object

Page 19: L12: REST Service

1919

REST-Service

Buildingascript resource (Createanew JavaScript)

Theleft button always adds anewconfiguration object

Page 20: L12: REST Service

2020

REST-Service

Buildingascript resource (Createanew JavaScript)

Astub for the JavaScriptisgenerated

„parameters“are the RESTparameters defined inframework

Page 21: L12: REST Service

2121

REST-Service

Buildingascript resource (Addaparameter)

Theleft button always adds anewconfiguration object

Page 22: L12: REST Service

2222

REST-Service

Buildingascript resource (Choose aparameter type)

Theleft button always adds anewconfiguration object

Page 23: L12: REST Service

2323

REST-Service

Buildingascript resource (Compute something)

Theleft button always adds anewconfiguration object

Page 24: L12: REST Service

2424

REST-Service

Buildingascript resource (Testthe script)

Theleft button always adds anewconfiguration object

Page 25: L12: REST Service

2525

REST-Service

Opening the request inthe browserhttp://localhost:8815/music/album/ID1405_147386337/songs

Page 26: L12: REST Service

2626

REST-Service

Built-inResources

• Pre-defined resources that are available inthe system

• Canbe added to services

• Coveroften encountered use-cases:• Accessing and changing blob attributes

• Object lists of objects,including sorting and filtering

• Accessing print templates and rendering with specified objects

• Accessing the configured icons of types

• ViewconfigMapper uses 3types of built-inresources

Page 27: L12: REST Service

2727

REST-Service

Built-inResources

Creating abuilt-inresource:

• Selectthe service into which the resource is to be embedded

• Clickonthe „Createnew Instances of RESTresource“button

• Choose „Instances of Built-inResource“

• Choose the desired kind of built-inResource• ActionResource

• BlobResource

• EditorConfigResource

• ObjectListPrintTemplateResource

• ObjectListPrintTemplateResourceWithFilename

• ObjectListResource

• TopicIconResource

Page 28: L12: REST Service

2828

REST-Service

Built-inResources

/blob/{blobLocator}

Allowed methods:GET,POST,PUT

Parameters:

• blobLocator:e.g.id of the blob attribute whose contents are to be retrieved or set

• binaryKey:used inmulti-partmessages to identify the corresponding part of the data

• overrideContentType:tells the database what content typeit really has to expect

• uploadOnly:boolean which controls whether the data willonly be sent to the database,result is aJSONstring that allows to refer to the created blob and set it inanother RESTcall

Examples:

GEThttp://localhost:8815/default/blob/ID43_1234567 fetches ablob from i-views

PUThttp://localhost:8815/default/blob/PP~ID43_1234~ID45_2345creates anew blob atobject with first id ofproperty typewith second id (Possible PropertyLocatorsyntax)

Page 29: L12: REST Service

2929

REST-Service

Builtin-inResources

/topicIcon/{topicID}

Allowed methods:GET

Parameters:

• topicID:(required)id of the object

• size:(optional)desired integerpixel size of the icon,expanded to point

• extensions:(optional)boolean,true allows returning icons of extension objects of the chosen topic

Examples:

GEThttp://localhost:8815/default/topicIcon/ID43_1234?size=10

Page 30: L12: REST Service

3030

REST-Service

Built-inResources

/{typeLocator}/objectList

Allowed methods:GET

Parameters:

• typeLocator:(required)id of the typewhose objects are to be displayed intable form

• name:(opt.)name of the object list configuration to be used

• application:(opt.)name of the application which determines the view config

• elements:(opt.)comma-separated locators for elements for the table

• elementsPath:(opt.)kpath-expressionthat willbe used to determine start objects

• startTopic:(opt.)id of topic to use as starting point for elementsPath

• sort:(opt.)expression for sorting (multi-sort possible)

• filter:(opt.)expression for filtering steps

Page 31: L12: REST Service

3131

REST-Service

Built-inResources

Parameterscont.:

• disableInheritance:(opt.)boolean to prevent descending into sub-types

• type:(opt.)string param to choose whether to display objects or sub-types of the given starting type

Remark:Although the parameter „application“is optionalit is essentialfor accessing the correct objectlist view configuration.Therefore always associate the table with the pre-defined application „REST“andadd the parameter „application=REST“to the request

Examples:

GEThttp://localhost:8815/Person/objectList?name=test&application=REST

render allpersons using object list config named „test“

GEThttp://localhost:8815/Person/objectList?sort=-1&filter=1~equals~g*

sort the table indescending order of values incolumn 1and filter with „g*“inthe first column

Page 32: L12: REST Service

3232

REST-Service

Built-inResources

/{conceptLocator}/objectList/printTemplate/{templateLocator}

Allowed methods:GET

Parameters:

• sameas objectList before

• templateLocator:(required)id of the print template object to be used to generate the output

Examples:

GEThttp://localhost:8815/default/Person/objectList/printTemplate/ID_46_3456

render allPersonobjects using the referenced print template

Page 33: L12: REST Service

3333

REST-Service

Built-inResources

/{conceptLocator}/objectList/printTemplate/{templateLocator}/{filename}

Sameas above,additionalparameter „filename“is notread,serves only to distinguish requests inthewebbrowser

Page 34: L12: REST Service

3434

REST-Service

Built-inResources

Configuring the built-inresources:

• Built-inresources encapsulate specific functionality,the only thing left to configure is whether thisinstance of resource needs authentication

• Additionally built-inresources offer the capability to define scripts which are executed before andafterthe request is computed to allow for changes inadvance and to further influence the responsethat the request computed• Preprocessing Script

• Postprocessing Script

• Thesescripts are created and maintained analogous to the scripts that are embedded into script RESTresources,they only provide differentfunction headers

Page 35: L12: REST Service

3535

REST-Service

Static FileResources

Static content can be referenced from within the RESTbridge.

• place content insub-directories of the installation directory of the RESTbridge

• declare the path pattern of the intended resources to map the relevantsub-directories

Example:

• installation directory of the bridge includes directory „icons“which contains the needed files

• create astatic file resource with path pattern „icons“,embed it into the service „test“

• request willlook likethis:

• GEThttp://localhost:8815/test/icons/file.png

Page 36: L12: REST Service

3636

REST-Service

Homework

1. Define ascript-resource that accepts astring parameter and responds by returning the given string

2. Define ascript-resource that allows to edit anattribute of your choice atanobject• Parametersfor value anto identify the object that is going to be edited

• Method

• Transactioncontrol!

• Errorhandling (e.g.incase of attribute value typemismatch)

3. Define abuilt-inresource that returns anobject list of allsongs• Remember to refer the specified object list to the application RESTwith the relation „apply in“!

Page 37: L12: REST Service

3737

Advanced:REST-Service

Sendyour questions to:[email protected]

Consultationhours:EveryWednesday

Thank you for visitingi-viewsUniversity

Page 38: L12: REST Service

3838

Advanced:REST-Service

UnsereneuenIcons