Skip to content

Latest commit

 

History

History
51 lines (39 loc) · 1.19 KB

endpoint.md

File metadata and controls

51 lines (39 loc) · 1.19 KB

Ulrack Web - Endpoint

Endpoints are defined as services and connected to routes. They perform the actual logic for an endpoint. They must implement the EndpointInterface.

An implementation of an endpoint looks like the following:

<?php

namespace MyVendor\MyProject;

use Ulrack\Web\Common\Endpoint\InputInterface;
use Ulrack\Web\Common\Endpoint\OutputInterface;
use Ulrack\Web\Common\Endpoint\EndpointInterface;

class EndpointTest implements EndpointInterface
{
    /**
     * Invokes the endpoint.
     *
     * @param InputInterface $input
     * @param OutputInterface $output
     *
     * @return void
     */
    public function __invoke(
        InputInterface $input,
        OutputInterface $output
    ): void {
        $output->setContentType('application/json');
        $output->setOutput($output->getAcceptedContentTypes());
    }
}

The $input the information sent with the incoming request. The $output contains a set of methods to manipulate the output for the response.

Further reading

Back to usage index

Request codecs

Error

Middleware

Routers