Start of change

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.
  • Specify the required REST service input parameters using JSON format key/value pairs in the HTTP body for the request.

Example

To invoke the default version of the service SYSIBMSERVICE.simpleSelect1, which has a single input String parameter named LOCATION, 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

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.

End of change