sessionapi

package module
v0.0.0-...-182a89d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2024 License: MIT Imports: 5 Imported by: 0

README

Cookies Example

This example illustrates how to read and write HTTP cookies from a Goa service.

The session service exposes two methods: create_session and use_session. create_session writes a cookie to the HTTP response and use_session reads it back.

The available DSL functions used to manipulate HTTP cookies are:

The following shows the DSL used to write the cookie:

HTTP(func() {
	POST("/")
	Response(StatusOK, func() {
		Cookie("session_id:SID") // Return session ID in "SID" cookie
		CookieMaxAge(3600)       // Sessions last one hour
	})
})

The value of the HTTP cookie SID is read from the session_id field of the method result object.

The extract below shows the DSL used to read the cookie:

HTTP(func() {
	GET("/")
	Cookie("session_id:SID") // Load session ID from "SID" cookie
	Response(StatusOK)
})

Building and Running the example

Build the server and the client:

go build ./cmd/session && go build ./cmd/session-cli

Run the server:

./session --http-port 8080

Run the client to create a session:

./session-cli -v -url http://localhost:8080 session create-session --body '{"name":"foo"}' 

Run the client to use a session:

./session-cli -url http://localhost:8080 session use-session -session-id abcd

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSession

func NewSession(logger *log.Logger) session.Service

NewSession returns the session service implementation.

Types

This section is empty.

Directories

Path Synopsis
cmd
gen

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL