1. Go to this page and download the library: Download jissanto/rapidrest library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jissanto / rapidrest example snippets
apidRest\Application;
use RapidRest\Http\Request;
use RapidRest\Http\Response;
$app = new Application();
// Add a route with a path parameter
$app->get('/hello/{name}', function (Request $request, string $name) {
return (new Response())
->withJson([
'message' => "Hello, $name!"
]);
});
// Run the application
$app->run();
class CreateUsersTable extends Migration
{
public function up(): void
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->boolean('is_active')->default(true);
$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('users');
}
}
class User extends Model
{
protected static string $table = 'users';
protected array $fillable = [
'name',
'email',
'password',
];
protected array $hidden = [
'password',
];
public function posts(): array
{
return $this->hasMany(Post::class);
}
public function profile(): Profile
{
return $this->hasOne(Profile::class);
}
}