Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

POST parameters support in RAML

Tags:

rest

api

raml

I'd like to ask if there is any support for POST parameters in RAML. And if there is - what is the syntax. I've browsed spec 0.8 and spec 1.0 roughly (actually I'm bound to 0.8, since many tools don't support 1.0 yet). I didn't find POST parameters support, but maybe I just missed something.

So what do I mean by POST parameters? These can be either of the two (sorry, I don't know their formal names, if there are any):

  • HTTP plain parameters, key=value, each parameter in one line, such as

    name=John Doe amount=5 which is not really handy (e.g. no nesting)

  • parameters as JSON object, just a JSON with all its syntax allowed (server-side needs to parse this json); such as:

    {"name":"John Doe","amount":"5"}

Different server-side API implementations use either 1st or 2nd one. Anyway, how does RAML support these?

like image 837
ducin Avatar asked Feb 16 '16 16:02

ducin


People also ask

What is ResourceType in RAML?

ResourceType is basically a template that is used to define the descriptions, methods, and parameters that can be used by multiple resources without writing the duplicate code or repeating code.

How do you write URI parameters in RAML?

URI Parameter is a variable element enclosed in curly braces {} inside relative URI of resources. Looking at above RAML, the URL to get employee details on the basis of employeeID will be GET /employees/{employeeID} where employees is resource and {employeeID} is URI parameter.

Can we have multiple request path in RAML?

No, its not possible to have two POST Method or any duplication of method to single resource is not possible. Even if you want to do this the as suggested make the required as false for the QueryParam and handle it inside the application with filters.


1 Answers

As it is shown in this reference https://github.com/raml-org/raml-spec/wiki/Breaking-Changes:

For raml 0.8:

body:
  application/x-www-form-urlencoded:
    formParameters:
      name:
        description: name on account
        type: string
        example: Naruto Uzumaki
      gender:
        enum: ["male", "female"]

Is the equivalent in raml 1.0 to:

body:
  application/x-www-form-urlencoded:
    properties:
      name:
        description: name on account
        type: string
        example: Naruto Uzumaki
      gender:
        enum: ["male", "female"]

So what it changes is the formParameters attribute to the properties one.

like image 172
Joan Vilà Avatar answered Sep 21 '22 18:09

Joan Vilà