API
Overview
The API module provides lightweight front-end endpoints, route matching helpers, a fluent wrapper around wp_remote_*, and ZIP download delivery. It is useful when you want simple public endpoints without building a full REST controller.
Types in this module
Lipe\Lib\Api\ApiLipe\Lib\Api\RouteLipe\Lib\Api\Wp_RemoteLipe\Lib\Api\Zip
Api
Registers a root /api/ rewrite endpoint and dispatches route-specific WordPress actions.
Key public methods
public function hook(): voidpublic function is_doing_api(): boolpublic function get_action(string $endpoint): stringpublic function get_url(?string $endpoint = null, array $data = []): stringpublic function get_root_url(): string
Example
<?php
use Lipe\Lib\Api\Api;
Api::init_once();
add_action(Api::in()->get_action('export'), function(array $args): void {
wp_send_json_success($args);
});
$url = Api::in()->get_url('export', ['post_type' => 'book']);
Route
Maps friendly URLs to a placeholder page and exposes helpers for checking and reading the current route.
Key public methods
public function add(string $url, array $args): voidpublic function get_current_route(): ?arraypublic function is_current_route(string $route): boolpublic function get_url_parameter(): stringpublic function get_title(string $title, int|\WP_Post $post): string
Example
<?php
use Lipe\Lib\Api\Route;
Route::in()->add('account/orders', [
'title' => 'Orders',
'post_type' => 'page',
]);
if (Route::in()->is_current_route('account/orders')) {
$order = Route::in()->get_url_parameter();
}
Wp_Remote
A fluent interface for building request arguments before calling WordPress HTTP functions. HTTP method constants (METHOD_GET, METHOD_POST, METHOD_HEAD, METHOD_PUT, METHOD_DELETE, METHOD_TRACE, METHOD_OPTIONS, METHOD_PATCH) are exposed for use with wp_remote_request().
Key public methods
public function header( string $key, string $value ): staticpublic function get_args(): array
Example
<?php
use Lipe\Lib\Api\Wp_Remote;
$args = ( new Wp_Remote( [] ) )
->header( 'Accept', 'application/json' )
->get_args();
$response = wp_remote_get( 'https://example.com/api/books', $args );
Zip
Handles creation and delivery of ZIP archives from a simple POST-driven endpoint.
Key public methods
public static function init(): voidpublic function handle_request(): voidpublic function build_zip( array $files, ?string $zip_name = null ): voidpublic function get_post_data_to_send( array $urls, ?string $name = null ): arraypublic function get_url_for_endpoint(): string
Example
<?php
use Lipe\Lib\Api\Zip;
Zip::init();
$form = Zip::in()->get_post_data_to_send([
content_url('uploads/report.pdf'),
content_url('uploads/data.csv'),
], 'reports');