Just is an extremely barebones REST API framework with zero dependencies used to build REST APIs.
Simple, lightweight. The way it should be.
Projects like Slim / Comet / Leaf exist and are amazing and there is no reason not to use them.
I built Just to solve a personal problem. From time to time I find myself replicating API endpoints found on-board network switches, gateways and other devices that are not easy to get a hold of.
Just lets me replicate these with ease.
Nope. No package manager. Just download the repo, remove the .git folder and add your own.
Set the not found message.
$api->setNotFound(['error'=>'Requested resource not found']);
Default value :
['error'=>'Route not found']
Run the configuration and accept requests.
Define a new GET endpoint
$api->get('/example/get', 'Controller\Example\ExampleController@getExample');
Define a new POST endpoint
$api->post('/example/post', 'Controller\Example\ExampleController@postExample');
Define a new PUT endpoint
Define a new DELETE endpoint
Define a new PATCH endpoint
Get environment variables defined in a .env file
#.env
NAME=Just
\Just\Environment::get('NAME'); // Just
An empty function to your own code to protect your endpoints.
Returns the current request URI without query params.
Returns the current request method
Returns all data input to the request from php://input
, $_GET
, $_POST
and dynamic request variables.
If $assoc is true, data will be returned as an assoc array, not an object.
$api->get('/example/user/{userId}/details', 'Controller\Example\ExampleController@getUserDetails')
`GET mywebapp.domain/example/user/70/details?filter=id,name&sensitive=false
public function getUserDetails(){
\Just\Request::input()->userId; // "70"
\Just\Request::input()->filter; // "id,name"
\Just\Request::input()->sensitive; // "false"
}
Ensure request includes all required parameters from all sources.
public function myRequestHandler(){
\Just\Request::requires([
'username',
'password'
]);
}
Return a JSON response with response code.
\Just\Response::json([
'message'=>'User Found!', 'data'=>$userData
]);