Example #1
0
// Function roBody configures a RequestOptions object with the appropriate type of body (XML, JSON)
func roBody(inOp *grequests.RequestOptions, inRq *tRequests) (rErr error) {
	// Is this a POST?
	if inRq.Method != "POST" {
		rErr = errors.New("ERROR: Fn roBody - expecting a POST but received a GET request")
		return
	}

	// Configure a JSON or XML request body
	switch inRq.Typebody {
	case "application/json":
		inOp.Headers = contJSON
		inOp.JSON = inRq.Body
	case "application/xml":
		inOp.Headers = contXML
		inOp.XML = inRq.Body
	default:
		rErr = errors.New("ERROR: Fn roBody - did not receive an XML or JSON request object")
	}

	return
}