Skip to content

Commit 1bcc9d5

Browse files
committed
Rename AsyncHttp to Http and enhance API documentation
- Rename AsyncHttp class to Http for cleaner API naming - Add comprehensive PHPDoc annotations for all HTTP methods including PSR-7 interface methods - Update all test files to use new Http class name - Remove sample and stress test files - Add missing use statements for HTTP interfaces and configuration classes - Expand method documentation to include request builder, streaming, and PSR-7 methods
1 parent ed3c88a commit 1bcc9d5

File tree

11 files changed

+66
-1788
lines changed

11 files changed

+66
-1788
lines changed

sample.php

Lines changed: 0 additions & 208 deletions
This file was deleted.

sample_http.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/Api/Http.php

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
use Rcalicdan\FiberAsync\Http\Request;
77
use Rcalicdan\FiberAsync\Http\Response;
88
use Rcalicdan\FiberAsync\Http\StreamingResponse;
9+
use Rcalicdan\FiberAsync\Http\CacheConfig;
10+
use Rcalicdan\FiberAsync\Http\RetryConfig;
11+
use Rcalicdan\FiberAsync\Http\Stream;
12+
use Rcalicdan\FiberAsync\Http\Interfaces\MessageInterface;
13+
use Rcalicdan\FiberAsync\Http\Interfaces\RequestInterface;
14+
use Rcalicdan\FiberAsync\Http\Interfaces\StreamInterface;
15+
use Rcalicdan\FiberAsync\Http\Interfaces\UriInterface;
916
use Rcalicdan\FiberAsync\Promise\Interfaces\CancellablePromiseInterface;
1017
use Rcalicdan\FiberAsync\Promise\Interfaces\PromiseInterface;
1118

@@ -16,19 +23,63 @@
1623
* including GET, POST, streaming, and file downloads. It abstracts away the
1724
* underlying handler and event loop management for a more convenient API.
1825
*
26+
* Direct HTTP methods from HttpHandler:
1927
* @method static PromiseInterface<Response> get(string $url, array<string, mixed> $query = []) Performs a GET request.
2028
* @method static PromiseInterface<Response> post(string $url, array<string, mixed> $data = []) Performs a POST request.
2129
* @method static PromiseInterface<Response> put(string $url, array<string, mixed> $data = []) Performs a PUT request.
2230
* @method static PromiseInterface<Response> delete(string $url) Performs a DELETE request.
2331
* @method static PromiseInterface<Response> fetch(string $url, array<int|string, mixed> $options = []) A flexible, fetch-like request method.
24-
* @method static PromiseInterface<StreamingResponse> stream(string $url, array<int|string, mixed> $options = [], ?callable $onChunk = null) Streams a response body.
32+
* @method static CancellablePromiseInterface<StreamingResponse> stream(string $url, array<int|string, mixed> $options = [], ?callable $onChunk = null) Streams a response body.
2533
* @method static CancellablePromiseInterface<array{file: string, status: int, headers: array<mixed>}> download(string $url, string $destination, array<int|string, mixed> $options = []) Downloads a file.
34+
*
35+
* Request builder methods:
2636
* @method static Request cache(int $ttlSeconds = 3600, bool $respectServerHeaders = true) Start building a request with caching enabled.
37+
* @method static Request cacheWith(CacheConfig $config) Start building a request with custom cache configuration.
2738
* @method static Request timeout(int $seconds) Start building a request with timeout.
39+
* @method static Request connectTimeout(int $seconds) Start building a request with connection timeout.
2840
* @method static Request headers(array<string, string> $headers) Start building a request with headers.
41+
* @method static Request header(string $name, string $value) Start building a request with a single header.
42+
* @method static Request contentType(string $type) Start building a request with Content-Type header.
43+
* @method static Request accept(string $type) Start building a request with Accept header.
2944
* @method static Request bearerToken(string $token) Start building a request with bearer token.
3045
* @method static Request basicAuth(string $username, string $password) Start building a request with basic auth.
3146
* @method static Request retry(int $maxRetries = 3, float $baseDelay = 1.0, float $backoffMultiplier = 2.0) Start building a request with retry logic.
47+
* @method static Request retryWith(RetryConfig $config) Start building a request with custom retry configuration.
48+
* @method static Request noRetry() Start building a request with retries disabled.
49+
* @method static Request redirects(bool $follow = true, int $max = 5) Start building a request with redirect configuration.
50+
* @method static Request verifySSL(bool $verify = true) Start building a request with SSL verification configuration.
51+
* @method static Request userAgent(string $userAgent) Start building a request with custom User-Agent.
52+
* @method static Request body(string $content) Start building a request with string body.
53+
* @method static Request json(array<string, mixed> $data) Start building a request with JSON body.
54+
* @method static Request form(array<string, mixed> $data) Start building a request with form data.
55+
* @method static Request multipart(array<string, mixed> $data) Start building a request with multipart data.
56+
*
57+
* PSR-7 Message interface methods (immutable with* methods):
58+
* @method static MessageInterface withProtocolVersion(string $version) Return an instance with the specified HTTP protocol version.
59+
* @method static array<string, string[]> getHeaders() Retrieves all message header values.
60+
* @method static bool hasHeader(string $name) Checks if a header exists by the given case-insensitive name.
61+
* @method static string[] getHeader(string $name) Retrieves a message header value by the given case-insensitive name.
62+
* @method static string getHeaderLine(string $name) Retrieves a comma-separated string of the values for a single header.
63+
* @method static MessageInterface withHeader(string $name, string|string[] $value) Return an instance with the provided value replacing the specified header.
64+
* @method static MessageInterface withAddedHeader(string $name, string|string[] $value) Return an instance with the specified header appended with the given value.
65+
* @method static MessageInterface withoutHeader(string $name) Return an instance without the specified header.
66+
* @method static StreamInterface getBody() Gets the body of the message.
67+
* @method static MessageInterface withBody(StreamInterface $body) Return an instance with the specified message body.
68+
* @method static string getProtocolVersion() Retrieves the HTTP protocol version as a string.
69+
*
70+
* PSR-7 Request interface methods:
71+
* @method static string getRequestTarget() Retrieves the message's request target.
72+
* @method static RequestInterface withRequestTarget(string $requestTarget) Return an instance with the specific request-target.
73+
* @method static string getMethod() Retrieves the HTTP method of the request.
74+
* @method static RequestInterface withMethod(string $method) Return an instance with the provided HTTP method.
75+
* @method static UriInterface getUri() Retrieves the URI instance.
76+
* @method static RequestInterface withUri(UriInterface $uri, bool $preserveHost = false) Returns an instance with the provided URI.
77+
*
78+
* Request streaming methods:
79+
* @method static CancellablePromiseInterface<StreamingResponse> streamPost(string $url, mixed $body = null, ?callable $onChunk = null) Streams the response body of a POST request.
80+
*
81+
* Request execution methods:
82+
* @method static PromiseInterface<Response> send(string $method, string $url) Dispatches the configured request.
3283
*/
3384
class Http
3485
{
@@ -79,7 +130,7 @@ public static function setInstance(HttpHandler $handler): void
79130
* Magic method to handle dynamic static calls.
80131
*
81132
* This enables both direct HTTP methods (get, post, etc.) and request builder methods
82-
* (cache, timeout, headers, etc.) to be called directly on AsyncHttp.
133+
* (cache, timeout, headers, etc.) to be called directly on Http.
83134
*
84135
* @param string $method The method name.
85136
* @param array<mixed> $arguments The arguments to pass to the method.
@@ -89,7 +140,7 @@ public static function __callStatic(string $method, array $arguments)
89140
{
90141
$handler = self::getInstance();
91142

92-
$directMethods = ['get', 'post', 'put', 'delete', 'fetch', 'stream', 'download'];
143+
$directMethods = ['get', 'post', 'put', 'delete', 'fetch', 'stream', 'download', 'createStream', 'createStreamFromFile'];
93144

94145
if (in_array($method, $directMethods)) {
95146
return $handler->{$method}(...$arguments);
@@ -106,4 +157,4 @@ public static function __callStatic(string $method, array $arguments)
106157

107158
throw new \BadMethodCallException("Method {$method} does not exist on " . static::class);
108159
}
109-
}
160+
}

src/Http/Handlers/HttpHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
/**
2222
* Core handler for creating and dispatching asynchronous HTTP requests.
2323
*
24-
* This class acts as the workhorse for the AsyncHttp Api, translating high-level
24+
* This class acts as the workhorse for the Http Api, translating high-level
2525
* requests into low-level operations managed by the event loop.
2626
*/
2727
class HttpHandler

0 commit comments

Comments
 (0)