LFT
  • Namespace
  • Class
  • Tree

Namespaces

  • Docoflow
    • Contracts
    • Entity
    • Facades
    • Models
    • Traits
  • Docolight
    • Agno
      • Traits
    • Container
    • Http
      • Contracts
    • Rest
      • Handler
      • Http
    • Support
      • Debug
      • Traits
  • Docotory
    • Traits
  • None

Classes

  • Headers
  • JsonResponse
  • MimeResponse
  • Response
  • ResponseFactory

Class JsonResponse

This is a simple abstraction over top an HTTP response. This provides methods to set the HTTP status, the HTTP headers, and the HTTP body. Please use this response only if you want to send a JSON response.

$response = new Docolight\Http\JsonResponse(new Docolight\Http\Headers());

// Or you can resolve via factory
// $response = with(new Docolight\Http\ResponseFactory())->produce('json');

// Move even shorter way
// $response = container('response')->produce('json');

// Set your header
$response->headers->set('Foo', 'Bar');

// Set your response status
$response->setStatus(202);

// Set your response body
$response->setBody(new Docolight\Support\Fluent(array('my_json_index' => 'my_json_value')));

// Send your response to client
$response->send();

// In shorter way
// response(
//    'json',
//    200,
//    new Docolight\Support\Fluent(array('my_json_index' => 'my_json_value')),
//    array('Foo' => 'Bar')
// )->send();
CApplicationComponent
Extended by Docolight\Http\Response implements ArrayAccess
Extended by Docolight\Http\MimeResponse
Extended by Docolight\Http\JsonResponse
Namespace: Docolight\Http
Author: Krisan Alfa Timur krisanalfa@docotel.co.id
Located at Docolight/Http/JsonResponse.php

Methods summary

public
# init( )

Initialize component.

Initialize component.

Overrides

Docolight\Http\Response::init
protected string
# getContentType( )

Get content type specified for this class.

Get content type specified for this class.

Returns

string
protected string
# convertToStringRepresentation( Docolight\Http\Contracts\Arrayable $body )

Convert to a string representation.

Convert to a string representation.

Parameters

$body

Returns

string
protected mixed
# getEmpty( )

Default empty data

Default empty data

Returns

mixed

Overrides

Docolight\Http\Response::getEmpty

Methods inherited from Docolight\Http\MimeResponse

finalize(), getBody(), innerWrite(), sendBody(), write()

Methods inherited from Docolight\Http\Response

__construct(), getLength(), getMessageForCode(), getStatus(), offsetExists(), offsetGet(), offsetSet(), offsetUnset(), prepareHeaders(), redirect(), send(), setBody(), setMessage(), setStatus()

Properties summary

Properties inherited from Docolight\Http\MimeResponse

$stringRepresentation

Properties inherited from Docolight\Http\Response

$body, $headers, $length, $messages, $status

LFT API documentation generated by ApiGen