How to define payload for post?


#1

How do I define what the payload should be for a POST? Neither uriParameters nor queryParameters fit the bill here.

I don’t see anything in the documentation about how to do this.


#2

Hi @tsa,
You have several ways to do this. It’s by defining the “body” of your post.
Example:

 post:
    description: The POST operation adds an object to a specified bucket using HTML forms.
    body:

Now, after the body, you need to specify the content-type (unless you are using a default one for the entire RAML). Depending of that content type, is the way you will define the payload.

For example:

 post:
    description: The POST operation adds an object to a specified bucket using HTML forms.
    body:
      application/x-www-form-urlencoded:
        formParameters:
          AWSAccessKeyId:
            description: The AWS Access Key ID of the owner of the bucket who grants an Anonymous user access for a request that satisfies the set of constraints in the Policy.
            type: string
          acl:
            description: Specifies an Amazon S3 access control list. If an invalid access control list is specified, an error is generated.
            type: string

Or if you prefer, you can define it’s a json or xml by using schemas. For example:

/jobs:
  displayName: Jobs
  post:
    description: Create a Job
    body:
      text/xml:
        schema: |
          <xs:schema attributeFormDefault="unqualified"
                     elementFormDefault="qualified"
                     xmlns:xs="http://www.w3.org/2001/XMLSchema">
            <xs:element name="api-request">
              <xs:complexType>
                <xs:sequence>
                  <xs:element type="xs:string" name="input"/>
                </xs:sequence>
              </xs:complexType>
            </xs:element>
          </xs:schema>
      application/json:
        schema: |
          {
            "$schema": "http://json-schema.org/draft-03/schema",
            "properties": {
                "input": {
                    "required": false,
                    "type": "string"
                }
            },
            "required": false,
            "type": "object"
          }

I actually got the examples from the RAML Specs.
I hope this helps. Don’t hesitate in asking again if needed.

Chers!
@nohorbee


#4

Thank you! That’s exactly what I needed. I could not find the application/json part before.


#5

Does the RAML object in the Raml-to-Java parser, contain the json schema and xsd schema links or text? I would like to somehow use that info to generate POJOs that are then used by client side SDKs and automation test code, as well as server side generated code.


#6

In POST payload can be directly send in the body.
Simply the following

/yourResouce:
post:
    description: Description of your post method
    body:

This will directly directly send the payload through body .
Reference :- https://github.com/raml-org/raml-spec/blob/master/versions/raml-08/raml-08.md

The POST in the specification is actually in yaml format which is base of RAML


#7

Hello,

Seems it is a very old thread, but as I am new to RAML so somebody might be able to help me.
Basically what I am trying to check is if it’s possible to provide example for application/x-www-form-urlencoded content type.

So I know how we provide examples for JSON and as @nohorbee used form-parameters, is fine. But I am just trying to provide example for application/x-www-form-urlencoded content type.

Hope my question makes sense. Thanks.


#8

Hi @bharwani.vijay, happy to give you a hand!

Would you mind posting a definition for you RAML that is using that media type? It would help me to understand what exactly you are looking for.


#9
#%RAML 1.0
title: Customer API
baseUri: http://localhost:8081/mfs-customer

types: 
  RefreshToken:
    type: string
    description: Refresh token
  AccessToken:
    type: string
    description: The token generated for access.
  UserType:
    type: integer
    description: The type of the User.
  Expiry:
    type: number
    description: The TTL for the token
  CounterToken:
    type: number
    description: Counter Token
  Message:
    type: string
    description: Optional message to show to user. 
  LoginResponse:
   type: object
   description: Login response
   properties: 
     responseMap: LoginResponseMap
     message: Message
  LoginResponseMap:
   type: object
   description: Customer Login Response
   properties: 
     refreshToken: RefreshToken
     accessToken: AccessToken
     userType: UserType
     expiry: Expiry
     counterToken: CounterToken
/login: 
  post:
    description: This API is used to login
    body: 
      application/x-www-form-urlencoded:      
        properties:
          msisdn:
            description: mobile number
            type: string
            required: true
          password:
            description: password
            type: string
            required: true
          pin:
            description: User PIN
            type: string
            required: true
    responses: 
      200:
        description: Authentication successful  
        body: 
          application/json:
            type: LoginResponse

@christian_vogel, Above is my RAML definition and I am trying to provide sample request in the RAML like we do for response.