PHPackages                             lkt/http-response - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. lkt/http-response

ActiveLibrary

lkt/http-response
=================

LKT HTTP Response

2.0.10(5mo ago)03013MITPHPPHP &gt;=8.1.0CI passing

Since Nov 7Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/lkt-php/lkt-http-response)[ Packagist](https://packagist.org/packages/lkt/http-response)[ RSS](/packages/lkt-http-response/feed)WikiDiscussions v2.0 Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (13)Used By (3)

LKT HTTP Response
=================

[](#lkt-http-response)

Installation
------------

[](#installation)

```
composer require lkt/http-response
```

Usage
-----

[](#usage)

Instantiate a new response instance with the generic constructor:

```
use Lkt\Http\Response;

Response::status(200, ['some' => 'data']);
```

Or you can instantiate it with all the more specific constructors:

```
use Lkt\Http\Response;

Response::ok(['some' => 'data']); // Same as: Response::status(200, ['some' => 'data']);
```

Constructor list
----------------

[](#constructor-list)

MethodStatus code::ok200::created201::accepted202::noContent204::multipleChoices300::movedPermanently301::found302::seeOther303::notModified304::badRequest400::unauthorized401::forbidden403::notFound404::methodNotAllowed405::internalServerError500::notImplemented501::badGateway502::serviceUnavailable503Configure HTTP headers
----------------------

[](#configure-http-headers)

The `Response` instance can handle some http header.

```
use Lkt\Http\Response;

$response = Response::ok(['hey' => 'how are you?']);

// Set content type to JSON (default Content Type)
$response->setContentTypeJSON();

// Or to text/html
$response->setContentTypeTextHTML();

// Also, you can set the expiration and max age:
$response->setCacheControlMaxAgeHeaderToOneYear(84600);
$response->setExpiresHeader(84600);

// Or use the shortcuts:
$response->setExpiresHeaderToOneDay();
$response->setExpiresHeaderToOneWeek();
$response->setExpiresHeaderToOneMonth();
$response->setExpiresHeaderToOneYear();

$response->setCacheControlMaxAgeHeaderToOneDay();
$response->setCacheControlMaxAgeHeaderToOneWeek();
$response->setCacheControlMaxAgeHeaderToOneMonth();
$response->setCacheControlMaxAgeHeaderToOneYear();

// Send the response
$response->sendContent();
```

Default content type
--------------------

[](#default-content-type)

The default content type for `Response` is JSON.

Sending text/html
-----------------

[](#sending-texthtml)

When using a text/html response, simply pass the string as an argument. By default, this will turn the response content type to `text/html`.

```
use Lkt\Http\Response;
$response = Response::ok('may the force be with you');

// Output content
$response->sendContent();
```

Sending files
-------------

[](#sending-files)

You can send a file in a similar way, only remember to refresh the MIME type

```
use Lkt\Http\Response;

// Get a string with the content of the file
$content = file_get_contents($pathToImage);

// Create a response
$response = Response::ok($content);

// Set the MIME type for the file
// Automatically detect the mime type from file extension
// Notice: If the extension wasn't detected, the response will turn into an octet-stream
$response->setContentTypeByFileExtension('jpg'); // It can be pdf, png, doc, docx, csv, ...

// Set the last modified header
$lastModified = filemtime($pathToImage);
$response->setLastModifiedHeader($lastModified);

// Turn it to download
$response->setContentDispositionAttachment('image.jpg');

// Output img content
$response->sendContent();
```

Supported file extensions
-------------------------

[](#supported-file-extensions)

`Response` implements [lkt/mime](https://github.com/lekrat/lkt-mime) to check file extensions [(see supported MIME)](https://github.com/lekrat/lkt-mime#supported-mime).

Examples
--------

[](#examples)

### Sending a valid JSON response

[](#sending-a-valid-json-response)

```
use Lkt\Http\Response;

return Response::ok(['some' => 'data']);
```

### Sending a valid text/html response

[](#sending-a-valid-texthtml-response)

```
use Lkt\Http\Response;

return Response::ok('Hello world!');
```

### Sending a forbidden response

[](#sending-a-forbidden-response)

```
use Lkt\Http\Response;

return Response::forbidden(); // Empty
return Response::forbidden(['some' => 'data']); // JSON info
return Response::forbidden('Forbidden'); // text/html info
```

### Sending a file

[](#sending-a-file)

```
use Lkt\Http\Response;

return Response::ok(file_get_contents($pathToImage))
    ->setContentTypeByFileExtension('jpg')
    ->setLastModifiedHeader(filemtime($pathToImage));
```

### Downloading a file

[](#downloading-a-file)

```
use Lkt\Http\Response;

return Response::ok(file_get_contents($pathToImage))
    ->setContentTypeByFileExtension('jpg')
    ->setContentDispositionAttachment('image.jpg')
    ->setLastModifiedHeader(filemtime($pathToImage));
```

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance73

Regular maintenance activity

Popularity12

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~102 days

Recently: every ~212 days

Total

12

Last Release

154d ago

Major Versions

1.0.0 → 2.0.02022-12-28

PHP version history (2 changes)1.0.0PHP &gt;=7.2.0

2.0.0PHP &gt;=8.1.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/0915bfa65bb0c27057b7043d2b423137915e107411dd1684630508f2df076291?d=identicon)[lkt](/maintainers/lkt)

---

Top Contributors

[![alphaibanez](https://avatars.githubusercontent.com/u/24976472?v=4)](https://github.com/alphaibanez "alphaibanez (14 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lkt-http-response/health.svg)

```
[![Health](https://phpackages.com/badges/lkt-http-response/health.svg)](https://phpackages.com/packages/lkt-http-response)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
