Creating a Db2 REST service
You can use the Db2 REST service manager API, or createService API, to create a new user-defined service if you have the required authority. You can also issue the BIND SERVICE subcommand to create a new REST service.
Before you begin
Before you can create a service, you must apply APARs and create database objects that are required by the services. For instructions, see Enabling Db2 REST services.
Procedure
Example
This example shows how to create service simpleSelect1
for OWNER DB2GRP1
and QUALIFIER USRT002
and includes setting the Db2-Client-ApplName and Db2-Client-WrkStnName HTTP request header fields to the values "Customer Service" and "CS Laptop-47", respectively. Enter the following URI to start an HTTPS POST request:
POST https://host:port/services/DB2ServiceManager
Specify the following HTTP header fields for the request:
Accept:application/json
Content-Type:application/json
Db2-Client-ApplName:Customer Service
Db2-Client-WrkStnName:CS Laptop-47
Specify the following HTTP body for the request:
{
"requestType": "createService",
"sqlStmt": "SELECT DEPTNAME FROM DSN8B10.DEPT WHERE LOCATION = :LOCATION",
"collectionID": "SYSIBMSERVICE",
"serviceName": "simpleSelect1",
"description": "Select department name based on location.",
"owner": "DB2GRP1",
"qualifier": "USRT002"
}
Db2 returns the following response in JSON:
{
"StatusCode":201,
"StatusDescription":"DB2 Rest Service simpleSelect1 was created successfully.",
"URL": "http://<host>:<port>/services/SYSIBMSERVICE/simpleSelect1/V1"
"StatusOptions": {
"Applied":[
{
"ACTION": "ADD"
},
{
"VALIDATE": "RUN"
},
{
"EXPLAIN": "NO"
},
{
"ISOLATION": "CS"
},
{
"RELEASE": "COMMIT"
},
{
"OWNER": "DB2GRP1"
},
{
"QUALIFIER": "USRT002"
},
{
"APREUSE": ""
},
{
"APCOMPARE": ""
},
{
"BUSTIMESENSITIVE": "YES"
},
{
"SYSTIMESENSITIVE": "YES"
},
{
"ARCHIVESENSITIVE": "YES"
},
{
"APPLCOMPAT": "V12R1M500"
},
{
"DESCSTAT": "YES"
},
{
"SQLERROR": "NOPACKAGE"
},
{
"CURRENTDATA": "NO"
},
{
"DEGREE": "1"
},
{
"NODEFER": "PREPARE"
},
{
"REOPT": "NONE"
},
{
"IMMEDWRITE": "NO"
},
{
"DBPROTOCOL": "DRDA"
},
{
"OPTHINT": ""
},
{
"ENCODING": "UNICODE(01208)"
},
{
"CONCURRENTACCESSRESOLUTION": ""
},
{
"PATH": ""
},
{
"QUERYACCELERATION": ""
},
{
"GETACCELARCHIVE": ""
},
{
"ACCELERATOR": ""
},
}
The response shows that service simpleSelect1
was successfully created. Since version was not specified, the version of the service created defaults to V1.If necessary, you can issue the REBIND PACKAGE command to modify the options associated with service simpleSelect1
.