granitic: github.com/graniticio/granitic/facility/ws Index | Files

package ws

import "github.com/graniticio/granitic/facility/ws"

Package ws provides the JsonWs and XmlWs facilities which support JSON and XML web services.

This facility is documented in detail at http://granitic.io/1.0/ref/web-services

Web-services

Enabling the JsonWs or XmlWs facility allows the creation of web service endpoints where inbound and outbound data is automatically converted from and to JSON/XML.

An endpoint is created by adding an instance of handler.WsHandler with a corresponding implementation of handler.WsPostProcessor (generally referred to as handler logic) to your component definition file. For example:

"createRecordLogic": {
  "type": "inventory.CreateRecordLogic"
},

"createRecordHandler": {
  "type": "handler.WsHandler",
  "HTTPMethod": "POST",
  "Logic": "ref:createRecordLogic",
  "PathPattern": "^/record$",
}

See the ws and ws/handler package documentation for more information.

JSON

If JsonWs is enabled, any requests to a registered endpoint will have their request body parsed as JSON and any response rendered as JSON. This is handled with Go's built-in json package.

Many aspects of the parsing and rendering process (including content types, formatting of errors, pretty-printing and camel-case mapping) is configurable. Refer to http://granitic.io/1.0/ref/json for more details.

XML

Once the XmlWs facility is enabled, requests to an endpoint will, by default, be parsed as XML and rendered using user defined templates. Refer to http://granitic.io/1.0/ref/xml#templates for more details.

Alternatively, the XmlWs facility can be configured to automatically render responses as XML using Go's built-in XML marshalling components by setting the following configuration in your application's configuration files:

{
  "XmlWs": {
	"ResponseMode": "MARSHAL"
  }
}

Refer to http://granitic.io/1.0/ref/xml#marshalled for more information.

Many aspects of the parsing and rendering process (including content types and formatting of errors) is configurable. Refer to http://granitic.io/1.0/ref/xml for more details.

Index

Package Files

jsonbuilder.go ws.go xmlbuilder.go

type JsonWsFacilityBuilder Uses

type JsonWsFacilityBuilder struct {
}

Creates the components required to support the JsonWs facility and adds them the IoC container.

func (*JsonWsFacilityBuilder) BuildAndRegister Uses

func (fb *JsonWsFacilityBuilder) BuildAndRegister(lm *logging.ComponentLoggerManager, ca *config.ConfigAccessor, cn *ioc.ComponentContainer) error

See FacilityBuilder.BuildAndRegister

func (*JsonWsFacilityBuilder) DependsOnFacilities Uses

func (fb *JsonWsFacilityBuilder) DependsOnFacilities() []string

See FacilityBuilder.DependsOnFacilities

func (*JsonWsFacilityBuilder) FacilityName Uses

func (fb *JsonWsFacilityBuilder) FacilityName() string

See FacilityBuilder.FacilityName

type XmlWsFacilityBuilder Uses

type XmlWsFacilityBuilder struct {
}

Creates the components required to support the XmlWs facility and adds them the IoC container.

func (*XmlWsFacilityBuilder) BuildAndRegister Uses

func (fb *XmlWsFacilityBuilder) BuildAndRegister(lm *logging.ComponentLoggerManager, ca *config.ConfigAccessor, cc *ioc.ComponentContainer) error

See FacilityBuilder.BuildAndRegister

func (*XmlWsFacilityBuilder) DependsOnFacilities Uses

func (fb *XmlWsFacilityBuilder) DependsOnFacilities() []string

See FacilityBuilder.DependsOnFacilities

func (*XmlWsFacilityBuilder) FacilityName Uses

func (fb *XmlWsFacilityBuilder) FacilityName() string

See FacilityBuilder.FacilityName

Package ws imports 11 packages (graph) and is imported by 1 packages. Updated 2018-09-02. Refresh now. Tools for package owners.