MCPcopy Create free account
hub / github.com/kataras/iris / ReadJSON

Method ReadJSON

x/client/client.go:400–425  ·  view source on GitHub ↗

ReadJSON binds "dest" to the response's body. After this call, the response body reader is closed.

(ctx context.Context, dest interface{}, method, urlpath string, payload interface{}, opts ...RequestOption)

Source from the content-addressed store, hash-verified

398// ReadJSON binds "dest" to the response's body.
399// After this call, the response body reader is closed.
400func (c *Client) ReadJSON(ctx context.Context, dest interface{}, method, urlpath string, payload interface{}, opts ...RequestOption) error {
401 if payload != nil {
402 opts = append(opts, RequestHeader(true, contentTypeKey, contentTypeJSON))
403 }
404
405 resp, err := c.Do(ctx, method, urlpath, payload, opts...)
406 if err != nil {
407 return err
408 }
409 defer c.DrainResponseBody(resp)
410
411 if resp.StatusCode >= http.StatusBadRequest {
412 return ExtractError(resp)
413 }
414
415 // DBUG
416 // b, _ := io.ReadAll(resp.Body)
417 // println(string(b))
418 // return json.Unmarshal(b, &dest)
419
420 if dest != nil {
421 return json.NewDecoder(resp.Body).Decode(&dest)
422 }
423
424 return json.NewDecoder(resp.Body).Decode(&dest)
425}
426
427// ReadPlain like ReadJSON but it accepts a pointer to a string or byte slice or integer
428// and it reads the body as plain text.

Callers 15

testSessionsFunction · 0.45
TestFlashMessagesFunction · 0.45
AddMethod · 0.45
UpdateMethod · 0.45
CreateMethod · 0.45
UpdateMethod · 0.45
PartialUpdateMethod · 0.45
CreateMethod · 0.45
UpdateMethod · 0.45
PartialUpdateMethod · 0.45
InsertProductsMethod · 0.45
mainFunction · 0.45

Calls 5

DoMethod · 0.95
DrainResponseBodyMethod · 0.95
RequestHeaderFunction · 0.85
ExtractErrorFunction · 0.85
DecodeMethod · 0.65

Tested by 5

testSessionsFunction · 0.36
TestFlashMessagesFunction · 0.36
TestGetBindingsForFuncFunction · 0.36
BeforeActivationMethod · 0.36
TestClientJSONFunction · 0.36