Setting up Db2 REST server metadata on Cloud Pak for Data

Before application programmers can create REST services, they need to set up the REST server metadata.

You need to issue the following REST call. If the schema property is omitted, the REST metadata is created in the schema DB2REST.

def setup_metadata():
    #If the schema is not specified DB2REST will be used. 
    schema = ""
    
    url = "https://%s:%s/v1/metadata/setup"% (restHostname,restPort)

    header = {
        "content-type": "application/json",
        "authorization": token
    }
    body = {
        "schema": schema
    }

    response = requests.post(url, verify = False, headers = header, json = body)
    if response.status_code != 201:
        print("Setup metadata failed")
        print(response.status_code, response.reason)
        print(response.json())
    else:
        print("Created setup metadata")
Notes:
  • The above example assumes that you have set an authentication token as described in Authenticating REST commands in Db2.
  • If you created an admin user, or granted admin privileges to a user from the Cloud Pak for Data web client, you must run the following two SQL grants before this user is considered an admin user by the Db2® REST service:
    GRANT SELECT ON SYSCAT.ROUTINEAUTH TO USER myuser
    GRANT SELECT ON SYSCAT.ROUTINES TO USER myuser
  • This topic illustrates how to setup REST metadata by using Python. You can follow a similar procedure to define services by using other programming languages such as Curl, Perl, or JavaScript.