Page system

The directory pages/ contains the entry points of a GOX application.

Each directory file pages/ defines an application page and can answer HTTP requests, run server logic and build the interface that will be sent to the client. The location of each file within the file system determines the route from which it will be available.

For example, a simple page could be defined as follows.

gox
module index

import "github.com/gox-lang/gox"

func GET(ctx *gox.Context) gox.Page {
    return <h1>Hola GOX</h1>
}

The pages use the GOX Template system to build the interface and can reuse components, run any Go logic and interact with the rest of the application.


Organization

All pages of an application are within the directory pages/.

text
my-project/

└── pages/
    ├── index.gox
    ├── about.gox
    └── users/
        ├── users.gox
        └── info.gox

The following routes are generated in this example.

text
/
/about
/users
/users/info

When the name of a file matches the name of the directory that contains it, GOX automatically eliminates the duplicate segment of the route. This allows to organize large applications without generating redundant URLs.


The page system

The page system is composed of several concepts that work together to respond to requests for an application.

  • Pages define the interface that will be sent in response to an HTTP request.
  • Routing use the file system to determine which page each URL responds.
  • Methods can respond to different HTTP methods within the same page.
  • Actions allow you to run server logic from the client using tipadas go functions.
  • Context provides access to the HTTP request and the running environment during a page processing.

Each of these concepts is developed independently in the relevant documentation.


Integration with Go

The page system is part of the GOX programming model and directly takes advantage of the features of the Go language.

This means that pages and Actions are normal Go functions, so they can use typed parameters, local variables, call to functions and any language control structure to build an HTTP response or run server logic.

In addition, the pages directly use the GOX Template system, so they can combine HTML, components and presentation logic without depending on external template engines.

To learn more about Templates, check your documentation.


See also

Next step

Continue with Pages to learn how to build pages and respond to HTTP requests using GOX.

Pages