RAML Code check basis of Requirement


#1

Hello,

I have below requirement for designing simple RAML. I’m newbie in RAML coding so would like to know if my codeis according to requirement or not

Requirement:

a) Has at least 1 endpoint with a GET and POST method.
b) Includes description attribute of the API
c) Includes description attribute of the method
d) The GET request takes a query parameter of "mulesoft"
e) Define the response with an object that contains least a string and integer data type
f) Includes an example for a 200 response code that matches the definition’s response object from above

My Code:

#%RAML 1.0
title: Coding_Champions
version: 1.0.development
baseUri: http://localhost:8004/api
description: This API displays and adds Organisation with details

types:
  Org:
    type: object
    properties:
      name: string
      address: string
      pincode: integer
/details:
  displayName: Company Details
  description: Coding challenge which takes query parameter of "mulesoft"

  get:
    description: Retrieve a list of all the Orgs
    queryParameters:
      mulesoft: 
       description: Specify the Org name that you want to retrieve
       type:    boolean
       required: true
    responses:
      200:
        body:
          application/json:
            type: Org
            examples:
              MuleSoft:
                name: MuleSoft
                address: 77 Geary Street, Suite 400
                pincode: 94108
  post:
      description: Add a Org to list
      body: 
        application/json: 
            type: Org
            examples:
              Cognizant:
                name: Cognizant
                address: DLF
                pincode: 9771
      responses: 
        201:
          body: 
            application/json:
              example: |
                {
                "message":"New Org updated but not really"
                }                    

Thanks


#2

Your RAML seems valid and to match the requirements your listed. Have you tried a mocking service like osprey-mocking-service? I find it very useful when writing RAML API definitions as it allows me to “visualize” what it looks like.

E.g. using your RAML:

$ npm install -g osprey-mock-service
$ osprey-mock-service -f api.raml -p 8004

then I can query (here using httpie):

$ http http://localhost:8004/api/details?mulesoft=true
HTTP/1.1 200 OK

[
    {
        "MuleSoft": {
            "address": "77 Geary Street, Suite 400",
            "name": "MuleSoft",
            "pincode": 94108
        }
    }
]

#3

@jstoiko thanks for your reply. I’m more of concerned with one of point in the requirement
"The GET request takes a query parameter of “mulesoft”

Does it mean I should give mulesoft as parameter dynamically in my url, If yes then other than mulesoft is passed as parameter then it should throw an error ?

(or)

Does it mean i need to hard code “mulesoft” in my RAML code as I have done now ?

Can you please clear me on this ?