Basics
All internals of the framework are exposed.
You can modify these internals, in fact it is intended for you to do so.
Note
You are also welcome to contribute back if you can.


Serve
You can start an http server with servers.Start() .
package main

import (
    "main/lib/core/routes"
    "main/lib/core/scopes"
    "main/lib/core/servers"
    "net/http"
)

var _ = servers.Start(servers.StartOptions{ // Starts server.
    Routes: []routes.Route{
        {
            Pattern: "GET /", 
            Handler: func(_ scopes.Scope, request *http.Request, writer http.ResponseWriter) {
                // ---> Handle request here. <---
            },
        },
    },
})


Path Fields
Route patterns can define dynamic path fields using {} syntax.
Path fields can then be retrieved with request.PathValue() .
package main

import (
    "main/lib/core/routes"
    "main/lib/core/scopes"
    "net/http"
)

var _ = routes.Route{
    Pattern: "GET /{name}",
    Handler: func(_ scopes.Scope, request *http.Request, _ http.ResponseWriter) {
        _ = request.PathValue("name") // Receives path field "name".
    },
}


Messages
Use io.ReadAll() to retrieve messages sent by the client.
package main

import (
    "io"
    "main/lib/core/routes"
    "main/lib/core/scopes"
    "net/http"
)

var _ = routes.Route{
    Pattern: "GET /",
    Handler: func(_ scopes.Scope, request *http.Request, _ http.ResponseWriter) {
        _, _ = io.ReadAll(request.Body) // Receives message.
    },
}
Use writer.Write() to send a message to the client.
package main

import (
    "main/lib/core/routes"
    "main/lib/core/scopes"
    "net/http"
)

var _ = routes.Route{
    Pattern: "GET /",
    Handler: func(_ scopes.Scope, _ *http.Request, writer http.ResponseWriter) {
        _, _ = writer.Write([]byte("hello")) // Sends message "hello".
    },
}


Headers Fields & Status
Use request.Header.Get() to retrieve header fields sent by the client.
package main

import (
    "main/lib/core/routes"
    "main/lib/core/scopes"
    "net/http"
)

var _ = routes.Route{
    Pattern: "GET /",
    Handler: func(_ scopes.Scope, request *http.Request, _ http.ResponseWriter) {
        _ = request.Header.Get("Accept") // Retrieves header field "Accept".
    },
}
Use writer.Header().Set() and writer.WriteHeader() to send header fields to the client.
package main

import (
    "main/lib/core/routes"
    "main/lib/core/scopes"
    "net/http"
)

var _ = routes.Route{
    Pattern: "GET /",
    Handler: func(_ scopes.Scope, _ *http.Request, writer http.ResponseWriter) {
        writer.Header().Set("Content-Type", "text/html") // Sets header field "Content-Type" 
                                                         // with value "text/html".
        writer.WriteHeader(200)                          // Sends status 200 and 
                                                         // header fields to the client.
    },
}


Queries
Use request.URL.Query().Get() to retrieve query fields.
package main

import (
    "main/lib/core/routes"
    "main/lib/core/scopes"
    "net/http"
)

var _ = routes.Route{
    Pattern: "GET /",
    Handler: func(_ scopes.Scope, request *http.Request, _ http.ResponseWriter) {
        _ = request.URL.Query().Get("name") // Retrieves query field "name".
    },
}


Forms
Use receive.Form() to receive content as multipart form or url encoded form when using POST and GET http verbs.
package main

import (
    "main/lib/core/receive"
    "main/lib/core/routes"
    "main/lib/core/scopes"
    "net/http"
)

var _ = routes.Route{
    Pattern: "GET /",
    Handler: func(_ scopes.Scope, request *http.Request, _ http.ResponseWriter) {
        var form struct {                // Creates a zero initialized form.
            Name string `form:"name"`
        }
        _ = receive.Form(request, &form) // Receives data into form.
    },
}
Tip
Form structs can define slices and files.
package main

import (
    "main/lib/core/receive"
    "main/lib/core/routes"
    "main/lib/core/scopes"
    "mime/multipart"
    "net/http"
)

var _ = routes.Route{
    Pattern: "GET /",
    Handler: func(_ scopes.Scope, request *http.Request, _ http.ResponseWriter) {
        var form struct {
            Name     string               `form:"name"`
            Comments []string             `form:"comments"` // Slice of strings.
            File     multipart.FileHeader `form:"file"`     // File handler.
        }
        _ = receive.Form(request, &form) // Receives data into form.
    },
}
You can open and read the file.
src, _ := form.File.Open()
dst, _ := os.Create("my-file.txt")
io.Copy(src, dst)
Remember to close your files.
defer src.Close()
defer dst.Close()


Json
Use receive.Json() to receive content as json when using POST and PUT http verbs and send.Json() to send json content.
package main

import (
    "main/lib/core/receive"
    "main/lib/core/routes"
    "main/lib/core/scopes"
    "main/lib/core/send"
    "net/http"
)

type GreetingDetails struct {   // Defines a struct in which to
    Name string `json:"name"` // store the json content.
}

var _ = routes.Route{
    Pattern: "GET /",
    Handler: func(_ scopes.Scope, request *http.Request, writer http.ResponseWriter) {
        var details GreetingDetails         // Creates a zero value.
        _ = receive.Json(request, &details) // Unmarshals the content into details.
        _ = send.Json(writer, details)      // Sends content back as json.
    },
}


Cookies
Use receive.Cookie() to retrieve cookies and send.Cookie() to send them.
package main

import (
    "main/lib/core/receive"
    "main/lib/core/routes"
    "main/lib/core/scopes"
    "main/lib/core/send"
    "net/http"
)

var _ = routes.Route{
    Pattern: "GET /",
    Handler: func(_ scopes.Scope, request *http.Request, writer http.ResponseWriter) {
        nickname, _ := receive.Cookie(request, "nickname") // Retrieves cookie "nickname".
        send.Cookie(writer, "nickname", nickname)          // Sends it back.
    },
}


Session Id
Use negotiate.SessionId() to negotiate a session session id with the client.
package main

import (
    "main/lib/core/negotiate"
    "main/lib/core/routes"
    "main/lib/core/scopes"
    "net/http"
)

var _ = routes.Route{
    Pattern: "GET /",
    Handler: func(_ scopes.Scope, request *http.Request, writer http.ResponseWriter) {
        _, _ = negotiate.SessionId(writer, request) // Negotiates session id and returns it.
    },
}
Note
The session id is retrieved from the client’s session-id cookie.
If the client doesn’t provide such cookie, negotiate.SessionId() creates a new session id and sends the cookie to the client.
Caution
Session id must always be negotiated before invoking writer.WriteHeader() .


Redirect
Use send.ToLocation() to redirect to another page.
package main

import (
    "main/lib/core/routes"
    "main/lib/core/scopes"
    "main/lib/core/send"
    "net/http"
)

var _ = routes.Route{
    Pattern: "GET /",
    Handler: func(_ scopes.Scope, _ *http.Request, writer http.ResponseWriter) {
        send.ToLocation(writer, "/some-other-page") // Sends client to some-other-page.
    },
}