2017 © Pedro Peláez
 

library sharesta

restful json api creation using strict hack

image

usox/sharesta

restful json api creation using strict hack

  • Monday, July 23, 2018
  • by usox
  • Repository
  • 2 Watchers
  • 4 Stars
  • 365 Installations
  • C++
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 17 Versions
  • 59 % Grown

The README.md

Sharesta - Strict HAck RESTful Apis

A micro framework to build simple and easy to use rest-like apis - written in strict hack (Hack)., (*1)

Usage

First, build some classes containing your logic.., (*2)


final class HomeRoute implements \JsonSerializable { public function jsonSerialize(): string { return 'Welcome home'; } } final class UpdateUserRoute implements \JsonSerializable { public function __construct( private int $user_id, private \Usox\Sharesta\RequestInterface $request ): void { } public function jsonSerialize(): bool { // do some magic, e.g. access the request body by $this->request return true; } }

Now create a class containing your route configurations., (*3)

final class Routes implements Usox\Sharesta\RoutesInterface {

    public function registerRoutes(Usox\Sharesta\RouterInterface $router): void {
        $router->get(
            '/',
            (Usox\Sharesta\RequestInterface $request): \JsonSerializable ==> {
                return new HomeRoute();
            }
        );

        /**
         * Get variables from the path (e.g. `http://some.tld/users/123`)
         */
        $router->post(
            '/users/:id',
            (Usox\Sharesta\RequestInterface $request): \JsonSerializable ==> {
                return new UpdateUserRoute(
                    $request->getUriValues('id'),
                    $request->getRequestBody()
                );
            }
        );
    }
}

Setup sharesta, register your routes and let the application controller handle your requests., (*4)

<?hh // strict

require_once 'vendor/autoload.php';

<<__Entrypoint>>
function main(): noreturn {
    /* HH_IGNORE_ERROR[2050] */ $get_vars = dict($_GET);
    /* HH_IGNORE_ERROR[2050] */ $server_vars = dict($_SERVER);

    $factory = new Usox\Sharesta\ApiFactory();
    $router = $factory->createRouter(
        $server_vars,
        $get_vars
    );

    $routes = new Routes();
    $routes->registerRoutes($router);

    $router->route(
        '' // path to the file. Leave it empty if your server configuration defaults to index.hh
    );

    die(0);
}

Example

See example/webroot/index.hh for an example., (*5)

The Versions

23/07 2018

dev-master

9999999-dev

restful json api creation using strict hack

  Sources   Download

MIT

The Requires

 

The Development Requires

api json restful hack hhvm

23/07 2018

v3.1.0

3.1.0.0

restful json api creation using strict hack

  Sources   Download

MIT

The Requires

 

The Development Requires

api json restful hack hhvm

19/06 2018

v3.0.1

3.0.1.0

restful json api creation using strict hack

  Sources   Download

MIT

The Requires

 

The Development Requires

api json restful hack hhvm

19/06 2018

3.0.0

3.0.0.0

restful json api creation using strict hack

  Sources   Download

MIT

The Requires

 

The Development Requires

api json restful hack hhvm

26/01 2018

2.0.x-dev

2.0.9999999.9999999-dev

restful json api creation using hack

  Sources   Download

MIT

The Requires

 

The Development Requires

api json restful hack hhvm

26/01 2018

v2.0.2

2.0.2.0

restful json api creation using hack

  Sources   Download

MIT

The Requires

 

The Development Requires

api json restful hack hhvm

27/09 2017

v2.0.1

2.0.1.0

restful json api creation using hack

  Sources   Download

MIT

The Requires

 

The Development Requires

api json restful hack hhvm

26/09 2017

v2.0.0

2.0.0.0

restful json api creation using hack

  Sources   Download

MIT

The Requires

 

The Development Requires

api json restful hack hhvm

05/06 2017

1.0.2

1.0.2.0

restful json api creation using hack

  Sources   Download

MIT

The Requires

  • hhvm >=3.9

 

The Development Requires

api json restful hack hhvm

05/06 2017

1.0.x-dev

1.0.9999999.9999999-dev

restful json api creation using hack

  Sources   Download

MIT

The Requires

  • hhvm >=3.9

 

The Development Requires

api json restful hack hhvm

26/05 2017

1.0.1

1.0.1.0

restful json api creation using hack

  Sources   Download

MIT

The Requires

  • hhvm >=3.9

 

The Development Requires

api json restful hack hhvm

12/03 2017

1.0.0

1.0.0.0

restful json api creation using hack

  Sources   Download

MIT

The Requires

  • hhvm >=3.9

 

The Development Requires

api json restful hack hhvm

09/03 2017

0.3.0

0.3.0.0

restful json api creation using hack

  Sources   Download

MIT

The Requires

  • hhvm >=3.9

 

The Development Requires

api json restful hack hhvm

09/03 2017

0.2.2

0.2.2.0

restful json api creation using hack

  Sources   Download

MIT

The Requires

  • hhvm >=3.9

 

The Development Requires

api json restful hack hhvm

09/03 2017

0.2.1

0.2.1.0

restful json api creation using hack

  Sources   Download

MIT

The Requires

  • hhvm >=3.9

 

The Development Requires

api json restful hack hhvm

09/03 2017

0.2.0

0.2.0.0

restful json api creation using hack

  Sources   Download

MIT

The Requires

  • hhvm >=3.12

 

The Development Requires

api json restful hack hhvm

07/08 2016

0.1.0

0.1.0.0

restful json api creation using hack

  Sources   Download

MIT

The Development Requires

api json restful hack hhvm