RespondJSON marshals the given response value and responds to the request. Additional headers can be passed using [WithHeaders] option.
(response any, opts ...RespondOpt)
| 120 | // RespondJSON marshals the given response value and responds to the request. |
| 121 | // Additional headers can be passed using [WithHeaders] option. |
| 122 | func (r *request) RespondJSON(response any, opts ...RespondOpt) error { |
| 123 | resp, err := json.Marshal(response) |
| 124 | if err != nil { |
| 125 | return ErrMarshalResponse |
| 126 | } |
| 127 | return r.Respond(resp, opts...) |
| 128 | } |
| 129 | |
| 130 | // Error prepares and publishes error response from a handler. |
| 131 | // A response error should be set containing an error code and description. |