Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify an optional element for a json request object

In API blueprint I am looking to specify an optional json element for a POST message. Example for;

    ### Add a new User [POST]
    To add a User send a JSON .....

    + Request (application/json)

    {
         "name": "A name",
         "age": 30
    }

How do I indicate to reader of API that age is optional in API call but still show that it's an integer?

~Colin

like image 363
colinbes Avatar asked Mar 29 '14 17:03

colinbes


1 Answers

I recommend table of document fields like this one.

### Source Fields

| field      | required | type | example                                | description |
|------------|:-:|-------------|----------------------------------------|-------------|
| name       | * | string      | `average-lead-time-frontend`           | Unique name for machines, used as reference key and for url usage. |
| title      | * | string      | `Average Lead Time Frontend`           | Title for humans. |
| sourcetype | * | string      | `team-avgLeadTime`                     | Source type identificator. |
| groups     |   | list        | `["engagement-analytics", "builder"]`  | List of groups where entity is member. |
| options    |   | object      | `{ "team": 21926 }`                    | Addition options for sourcetype. |
| data       |   | list        | `[70.3, 31.8]`                         | Actual data held by Source. |

Generated table of fields: http://i.stack.imgur.com/cxocx.png enter image description here

like image 180
daviddddd Avatar answered Sep 16 '22 22:09

daviddddd