Sets the request body to the provided value and returns the request itself.

        Keyword arguments:
        body -- A UTF-8 string or bytes-like object which represents the request body.
559160
def with_body(self, body):
        # @todo take encoding into account
        
        try:
            self.body = body.encode('utf-8')
        except:
            try:
                self.body = bytes(body)
            except:
                raise ValueError("Request body must be a string or bytes-like object.")
        hasher = hashlib.sha256()
        hasher.update(self.body)
        digest = base64.b64encode(hasher.digest()).decode('utf-8')
        self.with_header("X-Authorization-Content-Sha256", digest)
        return self
1188887
def set_request_body!(request)
      case @request_format
        when :json then request.body = (camelize_keys! @body).to_json
        when :form then request.set_form_data @body
        when :file then request.body_stream = @body
      end if @body
    end
922728
def set_json_item(key, value):
    
    data = get_json()
    data[key] = value

    request = get_request()
    request["BODY"] = json.dumps(data)
170943
@Deprecated
  public RequestTemplate body(byte[] bodyData, Charset charset) {
    this.body(Request.Body.encoded(bodyData, charset));

    return this;
  }
566108
def text(
    body, status=200, headers=None, content_type="text/plain; charset=utf-8"
):
    
    return HTTPResponse(
        body, status=status, headers=headers, content_type=content_type
    )
1242595
def update(self, body):
        
        json = None
        if body:
            json = self._json(self._post(self._api, data={'body': body}), 200)

        if json:
            self._update_(json)
            return True
        return False
910320
def encode_body_for_create
      if self.body.present?        
        if binary?
          self.body = Base64.encode64(self.body)
        elsif
          denc = detect_encoding
          self.body = self.body.encode('utf-8', denc)
        end
      end 

      true
    end
13314
private void prepareRequestBody() throws IOException {

    if (bodyByteArray != null) {
      setByteArrayBody();
    } else if (bodyString != null) {
      setStringBody();
    } else if (bodyObject != null) {
      setTypedBody();
    }
  }
833210
def _prepare_body(self):
        
        content_type = self.__consume
        if not content_type:
            content_type = self.__op.consumes[0] if self.__op.consumes else 'application/json'
        if self.__op.consumes and content_type not in self.__op.consumes:
            raise errs.SchemaError('content type {0} does not present in {1}'.format(content_type, self.__op.consumes))

        # according to spec, payload should be one and only,
        # so we just return the first value in dict.
        for parameter in self.__op.parameters:
            parameter = final(parameter)
            if getattr(parameter, 'in') == 'body':
                schema = deref(parameter.schema)
                _type = schema.type
                _format = schema.format
                name = schema.name
                body = self.__p['body'][parameter.name]
                return content_type, self.__op._mime_codec.marshal(content_type, body, _type=_type, _format=_format, name=name)
        return None, None
829038
def _decode_body(content_type: Optional[str], body: bytes,
                 *, strict: bool = False) -> Any:
    
    type_, encoding = _parse_content_type(content_type)
    if not len(body) or not content_type:
        return None
    decoded_body = body.decode(encoding)
    if type_ == "application/json":
        return json.loads(decoded_body)
    elif type_ == "application/x-www-form-urlencoded":
        return json.loads(urllib.parse.parse_qs(decoded_body)["payload"][0])
    elif strict:
        raise ValueError(f"unrecognized content type: {type_!r}")
    return decoded_body
22009
def set_header(self, header, value):
        
        # requests>=2.11 only accepts `str` or `bytes` header values
        # raising an exception here, instead of leaving it to `requests` makes
        # it easy to know where we passed a wrong header type in the code.
        if not isinstance(value, (str, bytes)):
            raise TypeError("header values must be str or bytes, but %s value has type %s" % (header, type(value)))
        self._headers[header] = value
239537
def _default_body(self):
        
        if not self.data:
            return ""
        if self.content_type == 'application/json':
            import json
            return json.dumps(self.data)
        elif self.content_type == 'application/x-www-form-urlencoded':
            import urllib
            return urllib.urlencode(self.data)
        else:
            raise NotImplementedError(
                "You must manually encode the request "
                "body for '{}'".format(self.content_type)
            )
741642
def body(value=nil, &block)
      if block_given?
        def block.each; yield(call) end
        response.body = block
      elsif value
        response.body = value
      else
        response.body
      end
    end
753509
def _update_response_body(self, resource):
        
        rpr = self._get_response_representer(resource)
        # Set content type and body of the response.
        self.request.response.content_type = \
                                rpr.content_type.mime_type_string
        rpr_body = rpr.to_bytes(resource)
        self.request.response.body = rpr_body
357328
def treat(request_body):
    
    # Python 3+ support
    if isinstance(request_body, six.binary_type):
        request_body = request_body.decode('utf-8')

    try:
        data = json.loads(request_body)
    except ValueError:
        raise exceptions.UnknownAPIResource('Request body is malformed JSON.')

    unsafe_api_resource = APIResource.factory(data)

    try:
        consistent_api_resource = unsafe_api_resource.get_consistent_resource()
    except AttributeError:
        raise exceptions.UnknownAPIResource('The API resource provided is invalid.')

    return consistent_api_resource
366780
function parseBody(req) {
    return extractBody(req)
        .then(() => {
            if (req.body && typeof req.body === 'object') return req.body;
            try {
                return JSON.parse(req.body);
            } catch (err) {
                throw Error('Unexpected body format received. Expected application/json, received: ' + req.body);
            }
        });
}
816155
def body(self):
        
        if self._body is None:
            if self._fieldstorage is not None:
                raise ReadBodyTwiceError()

            clength = int(self.environ('CONTENT_LENGTH') or 0)
            self._body = self._environ['wsgi.input'].read(clength)
            if isinstance(self._body, bytes):
                self._body = self._body.decode('utf8')

        return self._body