first project
هذا المحتوى غير متوفر بلغتك بعد.
First Project: Build a Todo API
Section titled “First Project: Build a Todo API”This guide builds a simple Todo API end-to-end using ɳSelf. No frontend, pure backend API with GraphQL and JWT auth.
1. Initialize the Project
Section titled “1. Initialize the Project”mkdir todo-api && cd todo-apinself init --name todo-api --domain localhostAccept all defaults. This generates a .env file with secure random secrets.
2. Start the Stack
Section titled “2. Start the Stack”nself buildnself startWait for all services to show healthy. Then confirm URLs:
nself urls3. Open the Hasura Console
Section titled “3. Open the Hasura Console”nself db hasura consoleThis opens https://localhost/hasura/console in your browser. The admin secret is in your .env as HASURA_GRAPHQL_ADMIN_SECRET.
4. Create the todos Table
Section titled “4. Create the todos Table”In the Hasura Console:
- Click Data → Create Table
- Table name:
todos - Add columns:
id: UUID, primary key, default:gen_random_uuid()title: Text, not nulldone: Boolean, not null, default:falsecreated_at: Timestamptz, default:now()
- Click Add Table
5. Track the Table
Section titled “5. Track the Table”Hasura will prompt you to track the new table. Click Track to expose it in the GraphQL API.
6. Insert and Query Data
Section titled “6. Insert and Query Data”In the GraphiQL explorer, insert a todo:
mutation { insert_todos_one(object: { title: "Learn nSelf" }) { id title done created_at }}Then query all todos:
query { todos { id title done created_at }}7. Test JWT Auth
Section titled “7. Test JWT Auth”The Auth service is running at https://localhost/auth/. Register a user:
curl -X POST https://localhost/auth/signup/email-password \ -H "Content-Type: application/json" \ -d '{"email":"dev@example.com","password":"password123"}'The response includes a JWT token. Use it in subsequent GraphQL requests:
curl -X POST https://localhost/v1/graphql \ -H "Authorization: Bearer <jwt_token>" \ -H "Content-Type: application/json" \ -d '{"query":"{ todos { id title } }"}'Set up row-level security in Hasura permissions to restrict rows by user ID.
8. Stop When Done
Section titled “8. Stop When Done”nself stopNext: Architecture · Plugin Catalog