Optional Parameters in a REST API


#1

How do you use multiple optional parameters in a restful API?

The documentation for creating an API and the URL to call it are pretty clear.

@restful(endpoint='milk')
type Milkmaid {

  @restful(subPath='cow/{fat}')
  cowMilk: function(fat: !string)

  @restful(subPath='goat')
  goatMilk: function()
}

Associated URL: /api/1/milk/cow/skim

What would need to be done if you wanted to replace the required parameter with multiple optional parameters?

What would the URL look like to call the API?


#2

I believe you would just call the API with query params.

Example:

@restful(endpoint='milk')
type Milkmaid {
  @restful(subPath='cow')
  cowMilk: function(fat: string, numContainers: int)
}

HTTP requests:

/api/1/milk/cow?fat=skim
/api/1/milk/cow?numContainers=4
/api/1/milk/cow?fat=skim&numContainers=4