Documentation

Overview

Package ws provides the JSONWs and XMLWs facilities which support JSON and XML web services.

This facility is documented in detail at https://granitic.io/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 https://granitic.io/ref/json-web-services 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 https://granitic.io/ref/xml-web-services 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 https://granitic.io/ref/xml-web-services for more information.

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JSONFacilityBuilder

type JSONFacilityBuilder struct {
}

    JSONFacilityBuilder creates the components required to support the JSONWs facility and adds them the IoC container.

    func (*JSONFacilityBuilder) BuildAndRegister

      BuildAndRegister implements FacilityBuilder.BuildAndRegister

      func (*JSONFacilityBuilder) DependsOnFacilities

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

        DependsOnFacilities implements FacilityBuilder.DependsOnFacilities

        func (*JSONFacilityBuilder) FacilityName

        func (fb *JSONFacilityBuilder) FacilityName() string

          FacilityName implements FacilityBuilder.FacilityName

          type XMLFacilityBuilder

          type XMLFacilityBuilder struct {
          }

            XMLFacilityBuilder creates the components required to support the XMLWs facility and adds them the IoC container.

            func (*XMLFacilityBuilder) BuildAndRegister

              BuildAndRegister implements FacilityBuilder.BuildAndRegister

              func (*XMLFacilityBuilder) DependsOnFacilities

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

                DependsOnFacilities implements FacilityBuilder.DependsOnFacilities

                func (*XMLFacilityBuilder) FacilityName

                func (fb *XMLFacilityBuilder) FacilityName() string

                  FacilityName implements FacilityBuilder.FacilityName