Genpact Cora Knowledge Center

Support

HTTP Service Example

Below is a sample HTTP service with GET method.

# Open API 3.0 reference - Link: https://swagger.io/docs/specification/about/
openapi: '3.0.0'
info:
  # Document title
  title: 'Sample HTTP Service Definition Name'
 
  # Document description
  description: 'Sample HTTP Service Definition Description'
 
  # Document version
  version: '1.0.0'
 
paths:
  # Sample HTTP GET operation with path parameter {id}
  /sampleGet/{param1}:
    get:
      parameters:
      - name: param1
        in: path
        description: 'Description for parameters 1'
        required: true
        schema:
          type: integer
      responses:
        '200':
          description: '[Operation successful response description]'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SampleSchema2'
      x-returned-errors:
        - Error1
      x-operation-handler:
        name: ExecuteWorkflow
        workflowSpaceId: '905e725a-305a-4cc5-98ce-83ab51667f33'
x-error-catalog:
  # Sample error 1
  - id: Error1
    code: ErrCode1
    title: 'Error 1 title'
    status: 400
    message: 'Error 1 message: {arg1}, {arg2}.'
    messageParameters:
    - name: arg1
    - name: arg2
  # Sample error 2
  - id: Error2
    code: ErrCode2
    title: 'Error 2 title'
    status: 410
    message: 'Error 2 message.'
components:
  schemas:
   
    # Sample schema 1:
    SampleSchema1:
      title: 'Sample Schema 1'
      type: object
      properties:
        property1:
          type: integer
        property2:
          type: string
    # Sample schema 2
    SampleSchema2:
      type: object
      properties:
        property1:
          type: string
        property2:
          type: integer
        property3:
          $ref: '#/components/schemas/SampleSchema1'
      required:
        - property1
        - property3

The right panel on Swagger displays the following UI format for the above YAML code sample:

 

After creating an HTTP listener, add the HTTP Input, Output and Fault activities to your workflow, from which The HTTP service is to be initiated, and bind these activities to the above YAML HTTP listener.

After all the bindings, hit the GET API with parameter as 21. The API goes to HTTP output activity and shows the following result:


For any parameter other than 21, the API goes to the HTTP fault activity and shows the following result: