1// Package restjson provides RESTful JSON serialization of AWS 2// requests and responses. 3package restjson 4 5//go:generate go run -tags codegen ../../../private/model/cli/gen-protocol-tests ../../../models/protocol_tests/input/rest-json.json build_test.go 6//go:generate go run -tags codegen ../../../private/model/cli/gen-protocol-tests ../../../models/protocol_tests/output/rest-json.json unmarshal_test.go 7 8import ( 9 "github.com/aws/aws-sdk-go/aws/request" 10 "github.com/aws/aws-sdk-go/private/protocol/jsonrpc" 11 "github.com/aws/aws-sdk-go/private/protocol/rest" 12) 13 14// BuildHandler is a named request handler for building restjson protocol 15// requests 16var BuildHandler = request.NamedHandler{ 17 Name: "awssdk.restjson.Build", 18 Fn: Build, 19} 20 21// UnmarshalHandler is a named request handler for unmarshaling restjson 22// protocol requests 23var UnmarshalHandler = request.NamedHandler{ 24 Name: "awssdk.restjson.Unmarshal", 25 Fn: Unmarshal, 26} 27 28// UnmarshalMetaHandler is a named request handler for unmarshaling restjson 29// protocol request metadata 30var UnmarshalMetaHandler = request.NamedHandler{ 31 Name: "awssdk.restjson.UnmarshalMeta", 32 Fn: UnmarshalMeta, 33} 34 35// Build builds a request for the REST JSON protocol. 36func Build(r *request.Request) { 37 rest.Build(r) 38 39 if t := rest.PayloadType(r.Params); t == "structure" || t == "" { 40 if v := r.HTTPRequest.Header.Get("Content-Type"); len(v) == 0 { 41 r.HTTPRequest.Header.Set("Content-Type", "application/json") 42 } 43 jsonrpc.Build(r) 44 } 45} 46 47// Unmarshal unmarshals a response body for the REST JSON protocol. 48func Unmarshal(r *request.Request) { 49 if t := rest.PayloadType(r.Data); t == "structure" || t == "" { 50 jsonrpc.Unmarshal(r) 51 } else { 52 rest.Unmarshal(r) 53 } 54} 55 56// UnmarshalMeta unmarshals response headers for the REST JSON protocol. 57func UnmarshalMeta(r *request.Request) { 58 rest.UnmarshalMeta(r) 59} 60