package
1.2.13
Repository: https://github.com/babelrpc/babel.git
Documentation: pkg.go.dev

# README

REST

This library reads attributes (i.e. annotations) in Babel files that represent RESTful service metadata.

Scope

All of the supported attributes must use the @rest scope.

Operation

The Op attribute may be used on a method to describe the RESTful operation.

OptionTypeDefaultDescription
Pathstring"/"The URL path.
Methodstring"GET"The HTTP method. (GET, PUT, POST, DELETE, OPTIONS, HEAD, or PATCH).
DeprecatedboolfalseWhether this method is deprecated.
HideboolfalseWhether to hide this operation from tools like babel2swagger.

Example

@rest [Op(Path="/test/{a}/parms", Method="POST", Deprecated=true)]

Response

Additional responses may be defined with the Response attribute. It is only valid on methods.

OptionTypeDefaultDescription
Codeint0The HTTP response code.
Typestring""The Babel data type of the response. Defaults to the return type of the method.
Descstring""Description of the response
Headersstring""A comma-separated list of header names. There must be a Header attribute with the same name.

Example

@rest [Response(Code=0, Type="string", Headers="Foo,Bar")]

Header

The Header attribute defines an HTTP headers that is returned.

OptionTypeDefaultDescription
Namestring""The HTTP header name.
Typestring""The Babel data type of the header.
Descstring""Description of the header.
Formatstring""The collection format of the data (applicable to list types): csv, ssv, tsv, pipes, multi.

Example

@rest [Header(Name="Foo", Type="string", Desc="Some header"),
       Header(Name="Bar", Type="list<string>", Format="csv" Desc="Some other header")]

Parameter

The Parm attribute defines where to pull variables from in the REST invocation.

OptionTypeDefaultDescription
Instring"query"Where the field is located: query, header, path, formdata, body.
RequiredboolfalseWhether the field is required.
Formatstring""The collection format of the data (applicable to list types): csv, ssv, tsv, pipes, multi.
Namestring""Used to rename a parameter (usually for headers)

Example

@rest [Parm(In="query", Required=false, Format="pipes")]