Creating and enabling Db2 native REST services
Create and enable Db2 native REST services that use the Db2 sample tables. These services are then used in subsequent scenarios.
About this task
employeeList
- Returns a list of employees.employeeDetails
- Returns the details of an individual employee.employeeUpdate
- Updates the details of an individual employee.
These services are created by using the Db2 service manager native REST service. Alternatively,
the BIND SERVICE subcommand can be used to create a new Db2 native REST service. For
example,
//FREE EXEC PGM=IKJEFT01,DYNAMNBR=20
//STEPLIB DD DSN=DSN1210.DB2.SDSNEXIT,DISP=SHR
// DD DSN=DSN1210.DB2.SDSNLOAD,DISP=SHR
//SYSTSPRT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//SYSTSIN DD *
DSN SYSTEM(DSN2)
FREE SERVICE("zCEEService"."selectEmployee")
//BIND EXEC PGM=IKJEFT01,DYNAMNBR=20
//STEPLIB DD DSN=DSN1210.DB2.SDSNEXIT,DISP=SHR
// DD DSN=DSN1210.DB2.SDSNLOAD,DISP=SHR
//SYSTSPRT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//DSNSTMT DD *
SELECT EMPNO AS "employeeNumber", FIRSTNME AS "firstName",
MIDINIT AS "middleInitial", LASTNAME as "lastName",
WORKDEPT AS "department", PHONENO AS "phoneNumber",
JOB AS "job"
FROM USER1.EMPLOYEE WHERE EMPNO = :employeeNumber
//SYSTSIN DD *
DSN SYSTEM(DSN2)
BIND SERVICE("zCEEService") -
NAME("selectEmployee") -
SQLENCODING(1047) -
DESCRIPTION('Select an employee from table USER1.EMPLOYEE')
/*
For each request in the following procedure, replace
<db2_host_name>
with the hostname of your Db2 instance and <db2_port>
with the port of your Db2 instance. You might also need to include authentication credentials such as
the Authorization HTTP header.
The services created in this scenario use the default Db2 collection SYSIBMSERVICE
.
Note: The
examples in this tutorial use Versioning support. If you do not have versioning, then remove the
version from body.
Procedure
Results
employeeList
, employeeDetails
, and employeeUpdate
are created as part of the SYSIBMSERVICE
collection in Db2.