Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to format a POST request on apiary.io?

thanks for your time I have a POST request that I want to document in the blueprint apiary, the header is something like this:

text/html

_method:POST

data[User][username]:

data[User][password]:

data[User][remember]:0

http://d.pr/i/uRFx

I have something like this but I am not sure how to finish it:

## login [/users/login/{username}{password}{remember}{ident}]
Login with a user and password

+ Parameters

    + username (required, string, `myname`) ... the username format should follow CakePHP: data[User][username].
    + password (required, string, `whatever`) ... the password format should follow CakePHP: data[User][password]
    + remember (required, number, `0`) ... the remember format should follow CakePHP: data[User][remember]
    + ident (optional, number, `0`) ... the ident format should follow CakePHP: data[User][ident]

### make login [POST]

+ login by user (text/plain)
What goes in here???????????

any idea? Thanks!

like image 865
lito Avatar asked Nov 07 '13 15:11

lito


People also ask

What is APIB file?

API Blueprint is a high-level language for describing web APIs. The syntax is a combination of Markdown syntax and Markdown Syntax for Object Notation (MSON), and the files are saved with a . apib extension.

How do you use apiary?

To use Apiary to design APIs, click 'Apiary'. Use your GitHub account to start API design. Once logged in, the UI gives an option to create a new API. Specify a name and click the “Create API” button.


1 Answers

Apparently this is submitting the data in a web form. In this case the Content-Type is of the application/x-www-form-urlencoded type.

The message-body of the request has special formatting and also some of its charters (square brackets) have to be %-escaped. For the details on the formatting of the request body see aforementioned Wiki article.

The API Blueprint in its simplest form could be something like:

# Login [/users/login]
## Make Login [POST]
+ Request (application/x-www-form-urlencoded)

        data%5BUser%5D%5Busername%5D=qq&data%5BUser%5D%5Bpassword%5Dqq&data%5BUser%5D%5Bremember%5D=0

+ Response 201

You should be able to see your example of request message-body in your traffic inspector under the "view URL encoded" link.

Refer to this blueprint to see this example in action.

Also refer to this SO question for further details on application/x-www-form-urlencoded.

like image 134
Zdenek Avatar answered Sep 21 '22 15:09

Zdenek