renanhangai / libweb-api
LibWeb API part
3.0.1
2019-10-09 18:22 UTC
Requires
- dflydev/fig-cookies: ^1.0
- phpdocumentor/reflection-docblock: ^4.3
- slim/slim: ^3.9
- violet/streaming-json-encoder: ^1.1
- webmozart/path-util: ^2.3
Suggests
- maximebf/debugbar: Provides better debug functionality
- phpdocumentor/reflection-docblock: Better generation of docs
- renanhangai/validator: Includes validation for request parameters
- dev-master
- 3.0.1
- 3.0.0
- 2.7.2
- 2.7.1
- 2.7.0
- v2.6.0
- v2.5.1
- v2.5.0
- v2.4.2
- v2.4.1
- v2.4.0
- v2.3.1
- v2.3.0
- v2.2.0
- v2.1.0
- v2.0.0
- v1.6.3
- v1.6.2
- v1.6.1
- v1.6.0
- v1.5.0
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.0
- v1.2.5
- 1.2.4
- 1.2.3
- 1.2.1
- 1.2.0
- 1.1.0
- 1.0.1
- 0.5.0
- 0.4.3
- 0.4.2
- 0.4.1
- 0.4.0
- 0.3.1
- 0.3.0
- 0.2.4
- 0.2.3
- 0.2.2
- v0.2.1
- 0.2.0
- 0.1.0
- 0.0.1
- dev-dependabot/npm_and_yarn/path-parse-1.0.7
- dev-dependabot/npm_and_yarn/hosted-git-info-2.8.9
- dev-dependabot/npm_and_yarn/lodash-4.17.21
- dev-dependabot/npm_and_yarn/handlebars-4.7.7
- dev-dependabot/npm_and_yarn/y18n-4.0.1
- dev-dependabot/npm_and_yarn/ini-1.3.7
- dev-dependabot/npm_and_yarn/yargs-parser-13.1.2
- dev-dependabot/npm_and_yarn/standard-version-8.0.1
This package is auto-updated.
Last update: 2025-03-01 00:12:13 UTC
README
Generate REST APIs with ease using slim framework
<?php $app = new \libweb\api\App; $app->get( "/", function() { return "hello world"; }); $app->run();
Will output
{ "status": "success", "data": "hello world", }
Methods
-
mapClass( $base, $class )
Ex:
$app->mapClass( "/test", "\\test\\api\\Test" );
Will be mapped to
$obj = new \test\api\Test( $app ); // "example.com/test/data" $obj->GET_data() // "example.com/test/info-name" $obj->GET_infoName() // "example.com/test/sub/dir/data" $obj->GET_sub_dir_data() // "example.com/test/sub-info/dir-name/data-user" $obj->GET_subInfo_dirName_dataUser()
-
mapPath( $base, $dir, $classTemplate )
Every path will be mapped to a file Ex:
$app->mapPath( "/test", "/project/test/", "\\myproject\\api\\test{path}{class}API" );
When entering to "example.com/test/user/books/data" Will be mapped to
require_once "/project/test/user/Books.php"; $obj = new \myproject\api\test\user\BooksAPI( $app ); $obj->GET_data()
Request
Inherits from \Slim\Http\Request
getValidatedParam( $name, $rule )
getValidatedParams( $rules )
$data = $req->getValidatedParams([ "name" => v::s(), "list" => v::arrayOf([ "id" => v::i(), "level?" => v::set(["N","R","W"]), ]), ]);
getValidatedParamsWithUpload( $rules )
Response
Inherits from \Slim\Http\Response
withFile( $file, $contentType = null )
withString( $buffer, $contentType = null )
withDownload( $file, $filename = null, $contentType = null, $mode = "attachment" )
withDownloadString( $buffer, $filename, $contentType = null, $mode = "attachment" )
withCookie( $key, $value, $options = array() )
withCookies( $cookies, $options = array() )
withJson( $data, $status = null )
withResponse( $data )