You are on page 1of 4

Design API with RAML

1. Login into Anypoint Platform


2. Go to Design Center
3. Click On + Create New button click on New API Spec from drop down
4. Specify ‘API Title’ as OYO Hotels REST API click on Create API Spec button
5. Define the operations in RAML as shown below

/hotels:
  get:
  post:
  /{hotelId}:
    get:
    put:
    delete:

    
6. Add query parameters to /hotels GET operations as shown below
/hotels:
  get:
    queryParameters:
      city:
        type: string
        required: true
        enum:
          - Hyderabad
          - Mumbai
          - Delhi
          - Bangalore
      priceUnder:
        type: integer
        required: false
        example: 2500
      startDate:
        type: string
        pattern: ^(([0-9])|([0-2][0-9])|([3][0-1])) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d{4}$
        example: 25 Oct 2020
        required: false
      endDate:
        type: string
        pattern: ^(([0-9])|([0-2][0-9])|([3][0-1])) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d{4}$
        required: false
        example: 28 Oct 2020

7. Click on the + button in the Files browser and create two folders with name examples and
dataTypes as shown below
8. Click on kebab menu (3 vertical dots menu) on the dataTypes folder  import
HotelDataType.raml file from ‘…\Training Data\Oyo Hotels\’ folder. Click on kebab menu on
examples folders  import HotelExample.raml and HotelsExample.raml files from ‘…\Training
Data\Oyo Hotels\’ folder as shown below

9. Define custom data type with name Hotel in the RAML by using below RAML definition. Use
yellow colour highlighted text from ‘Complete RAML’ word document that is attached below
FYR.

types:
  Hotel: !include dataTypes/
HotelDataType.raml

10. Add responses to /hotels GET operation. FYR use either the below snippet or open the below
file, use the yellow highlighted text from it

    responses:
      200:
        body:
          application/json:
            example: !include examples/
HotelsExample.raml
            type: Hotel[]
11. Add request body and responses to /hotels POST operation as shown below or use the file FYR

  post:
    body:
      application/json:
        example: !include examples/
HotelExample.raml
        type: Hotel
    responses:
      201:
        body:
          application/json:
            example: 
              message: Hotel has been added

12. Add responses to /hotels/{hotelId} GET operation

  /{hotelId}:
    get:
      responses:
        200:
          body:
            application/json:
              example: !include examples/
HotelExample.raml
              type: Hotel

13. Add request and responses to /hotels/{hotelId} PUT operation

    put:
      body:
        application/json:
          example: !include examples/
HotelExample.raml
          type: Hotel
      responses:
        200:
          body:
            application/json:
              example:
                message: Hotel has been updated

14. Add responses to /hotels/{hotelId} DELETE operation


    delete:
      responses:
        200:
          body:
            application/json:
              example:
                message: Hotel has been delete
d

End of the Lab

You might also like