Methods
A GOX page can declare multiple executable methods.
Each method represents an independent entry point within the page and is identified by the name of the function that declares it.
GOX recognizes two categories of methods:
- HTTP request methods.
- Actions.
Although both are part of the same page, they represent different categories and use different signatures.
HTTP request methods
HTTP request methods respond to traditional HTTP requests.
They are identified by reserved names that correspond to HTTP protocol methods.
func GET(ctx *gox.Context) gox.Page
func POST(ctx *gox.Context) gox.Page
func PUT(ctx *gox.Context) gox.Page
func PATCH(ctx *gox.Context) gox.Page
func DELETE(ctx *gox.Context) gox.Page All HTTP request methods return a type value gox.Page.
The parameter ctx provides access to the context of the current request.
Although a GOX page usually returns HTML content, an HTTP method can generate any type of GOX-supported HTTP response.
This allows the same programming model to be used to develop:
- Websites.
- APis REST.
- HTTP services.
- Hybrid applications that combine HTTP pages and endpoints.
The page statement and HTTP response construction are documented in:
The reusable components used by the pages are documented in:
Actions request methods
The actions represent executable operations defined by the application.
Unlike HTTP request methods, an action does not use a reserved name. Its name is defined by the developer.
func Login() gox.Action
func CreateUser() gox.Action
func DeleteAccount() gox.Action All actions return a type value gox.Action.
The accepted signatures, access to the context, invocation and conduct of the actions are documented in Actions.
Method selection
GOX automatically selects the corresponding method according to the type of request received.
For an HTTP request, GOX executes the method whose name matches the request method.
GET → GET
POST → POST
PUT → PUT
PATCH → PATCH
DELETE → DELETE For an action invocation, GOX executes the action whose name coincides with the action requested.
Login → Login
CreateUser → CreateUser
DeleteAccount → DeleteAccount In both cases, GOX executes a single method of the page.
Rules
All declared methods within the same page must have unique names.
The names reserved for HTTP methods cannot be used to declare actions.
The signature of each method should correspond to its category.
HTTP request methods:
func GET(ctx *gox.Context) gox.Page Actions:
func Login() gox.Action An HTTP request method must be returned gox.Page.
An action must return gox.Action.
The additional rules of actions, including their permitted signatures, parameters and access to the context, are documented in Actions.