Example operations table
This page displays an example operations table for HTTP requests with lua code.
-- The operations contained in the module. This maps the request/respons metadata to various
-- Lua script methods based on the nature of the request/response.
return {
operations = {
get_hello_world = {
-- Describes the operation which will be relayed to documentation definitions
description = "Example Operation",
-- The corresponding HTTP verb. Must be one of GET, POST, PUT, DELETE, HEAD, OPTIONS.
-- Note: If left unspecified, HEAD or OPTIONS will revert to a default behavior. Thereby
-- obviating the need to implement those under normal circumstances.
--
-- In the case of HEAD, a GET request will execute (if available) and then provide the
-- response without the headers.
--
-- The OPTIONS request will use the operations specified in this manifest file to determine
-- what requests are availble wihtout having to provide a specific implementation.
verb = "GET",
-- The path the server will resolve the module. The path parameters encapsulated in the
-- {} notation and will be used as wildcard-style matching. This example will match
-- any path under /hello_world/ and capture the remaining path componenet in the
-- foo path parameter.
path = "/hello_world/{foo}",
-- The lua method to call in the module when servicing the request. This will include
-- the get module.
method = "get",
-- Parameters which the request will accept. Parameters may ony specify simple types.
parameters = {
foo_number = "number",
bar_number = "number",
foo_string = "string",
bar_string = "string"
},
-- Specifies the content which will be produced and consumed by the operation. The consumer
-- will consume a model of the supplied type when the content type is provided.
consumes = {
-- Specifies the content-type to match the incoming requests
["application/json"] = {
-- Specifies the model which will be used to service the request
model = "foo",
-- Specifies any additional headers this request may consume
headers = {
["X-MyExampleStringHeader"] = {
description = "An example string header",
type = "string",
},
["X-MyExampleNumberHeader"] = {
description = "An example number header",
type = "number",
},
["X-MyExampleBooleanHeader"] = {
description = "An example boolean header",
type = "boolean",
}
}
}
},
produces = {
-- Specifies the content-type to match to the
["application/json"] = {
-- Specifies the model which will be used to service the request
model = "foo",
-- Specifies any additional headers this request may consume
headers = {
["X-MyExampleStringHeader"] = {
description = "An example string header",
type = "string",
},
["X-MyExampleNumberHeader"] = {
description = "An example number header",
type = "string",
},
["X-MyExampleBooleanHeader"] = {
description = "An example boolean header",
type = "string",
}
},
-- Specifies any options headers, if availble. These will be sent with the
-- response as-is. This is useful for performing operations such as CORS or
-- similar responses.
static_headers = {
["Access-Control-Allow-Origin"] = "http://example.com"
}
}
},
},
get_async_hello_world = {
-- Describes the operation which will be relayed to documentation definitions
description = "Example Operation",
-- The corresponding HTTP verb. Must be one of GET, POST, PUT, DELETE, HEAD, OPTIONS.
-- Note: If left unspecified, HEAD or OPTIONS will revert to a default behavior. Thereby
-- obviating the need to implement those under normal circumstances.
--
-- In the case of HEAD, a GET request will execute (if available) and then provide the
-- response without the headers.
--
-- The OPTIONS request will use the operations specified in this manifest file to determine
-- what requests are availble wihtout having to provide a specific implementation.
verb = "GET",
-- The path the server will resolve the module. The path parameters encapsulated in the
-- {} notation and will be used as wildcard-style matching. This example will match
-- any path under /hello_world/ and capture the remaining path componenet in the
-- foo path parameter.
path = "/hello_world_async/{foo}",
-- The lua method to call in the module when servicing the request. This will include
-- the get module.
method = "get_async",
-- Parameters which the request will accept. Parameters may ony specify simple types.
parameters = {
foo_number = "number",
bar_number = "number",
foo_string = "string",
bar_string = "string"
},
-- Specifies the content which will be produced and consumed by the operation. The consumer
-- will consume a model of the supplied type when the content type is provided.
consumes = {
-- Specifies the content-type to match the incoming requests
["application/json"] = {
-- Specifies the model which will be used to service the request
model = "foo",
-- Specifies any additional headers this request may consume
headers = {
["X-MyExampleStringHeader"] = {
description = "An example string header",
type = "string",
},
["X-MyExampleNumberHeader"] = {
description = "An example number header",
type = "number",
},
["X-MyExampleBooleanHeader"] = {
description = "An example boolean header",
type = "boolean",
}
}
}
},
produces = {
-- Specifies the content-type to match to the
["application/json"] = {
-- Specifies the model which will be used to service the request
model = "foo",
-- Specifies any additional headers this request may consume
headers = {
["X-MyExampleStringHeader"] = {
description = "An example string header",
type = "string",
},
["X-MyExampleNumberHeader"] = {
description = "An example number header",
type = "string",
},
["X-MyExampleBooleanHeader"] = {
description = "An example boolean header",
type = "string",
}
},
-- Specifies any options headers, if availble. These will be sent with the
-- response as-is. This is useful for performing operations such as CORS or
-- similar responses.
static_headers = {
["Access-Control-Allow-Origin"] = "http://example.com"
}
}
},
}
}
}
Last updated