abao icon indicating copy to clipboard operation
abao copied to clipboard

Test with POST data

Open AndreaCrotti opened this issue 8 years ago • 6 comments

I'm trying to test a simple API that takes an email in the POST data and return something else. So I defined my raml file like this:

/abao-check/:
  post:
    body:
      application/x-www-form-urlencoded:
        example: |
          {"email": "[email protected]"}

    responses:
      201:
        body:
          application/json:
            schema: |
              {
                "$schema": "http://json-schema.org/draft-03/schema",
                "type": "object",
                "required": ["email"],
                "properties": {"email": {"type": "string"}}
              }

but no matter what I do it doesn't seem it's never putting any body in request.POST. Any idea why?

Am I missing something obvious? by the way I think it would be great to have some examples of RAML files to test in this project, would make it easy to see what it can be done.. Thanks a lot!

AndreaCrotti avatar Jun 16 '16 14:06 AndreaCrotti

Abao doesn't currently support form-based submissions (a.k.a. application/x-www-form-urlencoded), only JSON-based media types.

As far as examples go, there are RAML/schema files in the test/fixtures folder.

plroebuck avatar Jun 17 '16 14:06 plroebuck

Sorry. I wrote response yesterday, but left without posting it.

plroebuck avatar Jun 17 '16 14:06 plroebuck

Ah ok thanks no problem @plroebuck I'll close the issue, is it a feature you want to implement anyway?

AndreaCrotti avatar Jun 20 '16 08:06 AndreaCrotti

@AndreaCrotti Abao support for url-encoded form data is something I hope to see added eventually as well, and I will contribute to that feature if I can. However I think in your case the problem is with the way you defined your specification. The data in your request example is clearly JSON, so I would recommend changing your specification to use a content-type of application/json:

/abao-check/:
  post:
    body:
      application/json:
        example: |
          {"email": "[email protected]"}

If that endpoint actually does accept a url-encoded form with an "email" field, putting JSON as the example for the request body is confusing. This tutorial on raml.org gives an example of how to document a form (using formParameters directive). http://raml.org/developers/raml-200-tutorial#body-parameters

coltonlw avatar Aug 15 '16 14:08 coltonlw

This is still an open issue right @coltonlw ?

AndreaCrotti avatar Sep 30 '16 20:09 AndreaCrotti

@AndreaCrotti I believe so, we are using Postman collections run via newman CLI runner for postman to test url encoded or multipart form data and file uploads

coltonlw avatar Oct 02 '16 16:10 coltonlw