Getting Started
First App
This guide builds one tiny API endpoint so you can feel the Netpress flow quickly.
We will create:
- a controller
- a service
- a route
- a JSON response
1. Create The App
npx create-netpress-app my-app
cd my-app
cp .env.example .env
npm run artisan -- key:generate
create-netpress-app installs dependencies for you by default. If you created the app with --skip-install, run npm install before continuing.
2. Generate A Controller
npm run artisan -- make:controller PingController
This creates:
app/Http/Controllers/PingController.js
3. Create A Service
Create app/Services/PingService.js:
export default class PingService {
static status() {
return {
framework: "Netpress",
status: "ok",
};
}
}
4. Update The Controller
import { BaseController } from "@admicaa/netpress";
import PingService from "../../Services/PingService.js";
class PingController extends BaseController {
async index(_req, res) {
return res.success(PingService.status());
}
}
export default new PingController();
The controller stays thin. It only handles the HTTP layer and delegates the work.
5. Register The Route
Open routes/api.js and add:
import PingController from "../app/Http/Controllers/PingController.js";
router.get("/ping", PingController.index);
6. Run The App
npm run dev
Then call the endpoint:
curl http://127.0.0.1:3000/api/v1/ping
Example response:
{
"success": true,
"data": {
"framework": "Netpress",
"status": "ok"
}
}
What You Just Used
Router()to register the endpointBaseControllerfor controller helpers- a service for business logic
res.success()for a predictable JSON response
That is the normal Netpress pattern.
Next, read Architecture Overview or Controllers.