Invoking a Db2 REST service

You can invoke a Db2 REST service through a RESTful HTTP client if you have the required authority.

Before you begin

You must have one of the following privileges or authorities to invoke a service:
  • Execute privilege on the package for the service
  • Ownership of the service
  • SYSADM or SYSCTRL authority
  • System DBADM.

Procedure

  • To invoke a service, issue an HTTP or HTTPS POST request through a REST client with the following URI format:
    POST https://<host>:<port>/services/<serviceCollectionID>/<serviceName>/<version>

    where

    • <serviceName> is the name of the service to be invoked.
    • <serviceCollectionID> is the collection-id for the service to be invoked.
    • <version> is the version identifier for REST service version to be invoked. The <version> portion of the URI is optional and is only valid to be used after REST service versioning has been enabled. If the <version> portion of the URI is not specified, then the default service version will be invoked.
  • Set the HTTP header Accept and Content-Type fields to application/json for the request.
  • Optional: Set any Db2 client information related HTTP header fields with values that will be assigned to the Db2 client information special registers. For more information, see Management of REST service client information.
  • Specify the required REST service input parameters using JSON format key/value pairs in the HTTP body for the request.

Example

This example shows how to invoke the default version of the service SYSIBMSERVICE.simpleSelect1, which has a single input String parameter named LOCATION. This example 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/SYSIBMSERVICE/simpleSelect1

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:

{
 "LOCATION": "<location>"
}

Db2 returns the following response in JSON:

{
 "ResultSet Output":
  {
   "DEPTNAME": "SPIFFY COMPUTER SERVICE DIV."
  },
  {
   "DEPTNAME": "PLANNING"
  },
  {
   "DEPTNAME": "INFORMATION CENTER"
  },
  {
   "DEPTNAME": "DEVELOPMENT CENTER"
  },
  {
   "DEPTNAME": "MANUFACTURING SYSTEMS"
  },
  {
   "DEPTNAME": "ADMINISTRATION SYSTEMS"
  },
  {
   "DEPTNAME": "SUPPORT SERVICES"
  },
  {
   "DEPTNAME": "OPERATIONS"
  },
  {
   "DEPTNAME": "SOFTWARE SUPPORT"
  },
  {
   "DEPTNAME": "BRANCH OFFICE F2"
  },
  {
   "DEPTNAME": "BRANCH OFFICE G2"
  },
  {
   "DEPTNAME": "BRANCH OFFICE H2"
  },
  {
   "DEPTNAME": "BRANCH OFFICE I2"
  },
  {
   "DEPTNAME": "BRANCH OFFICE J2"
  },
 "StatusCode": 200,
 "StatusDescription": "Execution Successful."
}

The response shows that service simpleSelect1 was successfully invoked.