rest

package module
v0.0.0-...-46bee30 Latest Latest
Warning

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

Go to latest
Published: May 24, 2022 License: BSD-3-Clause Imports: 20 Imported by: 0

README

REST Trigger

This trigger provides your flogo application the ability to start an action via REST over HTTP

Installation

flogo install github.com/TNTworks/flogo-contrib/trigger/rest

Configuration

Settings:
Name Type Description
port int The port to listen on - REQUIRED
enableTLS bool Enable TLS on the server
certFile string The path to PEM encoded server certificate
keyFile string The path to PEM encoded server key
Handler Settings:
Name Type Description
method string The HTTP method (ie. GET,POST,PUT,PATCH or DELETE) - REQUIRED
path string The resource path - REQUIRED
Output:
Name Type Description
pathParams params The path parameters (e.g., 'id' in http://.../pet/:id/name )
queryParams params The query parameters (e.g., 'id' in http://.../pet?id=someValue )
headers params The HTTP header parameters
method string The HTTP method used for the request
content any The content of the request
Reply:
Name Type Description
code int The http code to reply with
data any The data to reply with
headers params The HTTP response headers
cookies params The HTTP response cookies to set (uses 'Set-Cookie' headers)

Example Configurations

Triggers are configured via the triggers.json of your application. The following are some example configuration of the REST Trigger.

POST

Configure the Trigger to handle a POST on /device

{
  "triggers": [
    {
      "id": "flogo-rest",
      "ref": "github.com/TNTworks/flogo-contrib/trigger/rest",
      "settings": {
        "port": 8080
      },
      "handlers": [
        {
          "settings": {
            "method": "POST",
            "path": "/device"
          },
          "action": {
            "ref": "github.com/project-flogo/flow",
            "settings": {
              "flowURI": "res://flow:new_device_flow"
            }
          }
        }
      ]
    }
  ]
}
GET

Configure the Trigger to handle a GET on /device/:id

{
  "triggers": [
    {
      "id": "flogo-rest",
      "ref": "github.com/TNTworks/flogo-contrib/trigger/rest",
      "settings": {
        "port": 8080
      },
      "handlers": [
        {
          "settings": {
            "method": "GET",
            "path": "/device/:id"
          },
          "action": {
            "ref": "github.com/project-flogo/flow",
            "settings": {
              "flowURI": "res://flow:get_device_flow"
            },
            "input":{
              "deviceId":"=$.pathParams.id"
            }
          }
        }
      ]
    }
  ]
}

Documentation

Index

Constants

View Source
const (
	CorsPrefix = "REST_TRIGGER"
)
View Source
const HeaderSetCookie = "Set-Cookie"

Variables

This section is empty.

Functions

func TLS

func TLS(certFile, keyFile string) func(*Server)

TLS option enables TLS on the server

func Timeouts

func Timeouts(readTimeout, writeTimeout time.Duration) func(*Server)

Timeouts options lets you set the read and write timeouts of the server

Types

type Factory

type Factory struct {
}

func (*Factory) Metadata

func (*Factory) Metadata() *trigger.Metadata

Metadata implements trigger.Factory.Metadata

func (*Factory) New

func (*Factory) New(config *trigger.Config) (trigger.Trigger, error)

New implements trigger.Factory.New

type HandlerSettings

type HandlerSettings struct {
	Method string `md:"method,required,allowed(GET,POST,PUT,PATCH,DELETE)"` // The HTTP method (ie. GET,POST,PUT,PATCH or DELETE)
	Path   string `md:"path,required"`                                      // The resource path
}

type IDResponse

type IDResponse struct {
	ID string `json:"id"`
}

IDResponse id response object

type Output

type Output struct {
	PathParams  map[string]string `md:"pathParams"`  // The path parameters (e.g., 'id' in http://.../pet/:id/name )
	QueryParams map[string]string `md:"queryParams"` // The query parameters (e.g., 'id' in http://.../pet?id=someValue )
	Headers     map[string]string `md:"headers"`     // The HTTP header parameters
	Content     interface{}       `md:"content"`     // The content of the request
	Method      string            `md:"method"`      // The HTTP method used for the request
}

func (*Output) FromMap

func (o *Output) FromMap(values map[string]interface{}) error

func (*Output) ToMap

func (o *Output) ToMap() map[string]interface{}

type PreflightHandler

type PreflightHandler struct {
	// contains filtered or unexported fields
}

type Reply

type Reply struct {
	Code    int               `md:"code"`    // The http code to reply with
	Data    interface{}       `md:"data"`    // The data to reply with
	Headers map[string]string `md:"headers"` // The HTTP response headers
	Cookies []interface{}     `md:"cookies"` // "The response cookies, adds `Set-Cookie` headers"
}

func (*Reply) FromMap

func (r *Reply) FromMap(values map[string]interface{}) error

func (*Reply) ToMap

func (r *Reply) ToMap() map[string]interface{}

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(addr string, handler http.Handler, opts ...func(*Server)) (*Server, error)

func (*Server) Start

func (s *Server) Start() error

Start starts the server

func (*Server) Stop

func (s *Server) Stop() error

Stop stops the server

type Settings

type Settings struct {
	Port      int    `md:"port,required"` // The port to listen on
	EnableTLS bool   `md:"enableTLS"`     // Enable TLS on the server
	CertFile  string `md:"certFile"`      // The path to PEM encoded server certificate
	KeyFile   string `md:"keyFile"`       // The path to PEM encoded server key
}

type Trigger

type Trigger struct {
	// contains filtered or unexported fields
}

Trigger REST trigger struct

func (*Trigger) Initialize

func (t *Trigger) Initialize(ctx trigger.InitContext) error

func (*Trigger) Start

func (t *Trigger) Start() error

func (*Trigger) Stop

func (t *Trigger) Stop() error

Stop implements util.Managed.Stop

Directories

Path Synopsis
Cors package to validate CORS requests and provide the correct headers in the response
Cors package to validate CORS requests and provide the correct headers in the response

Jump to

Keyboard shortcuts

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