This project is a Todo List application built with Angular, and it uses json-server to simulate a backend API for tasks.
Run ng serve
for a dev server. Navigate to http://localhost:4200/
. The application will automatically reload if you change any of the source files.
To run a mock backend using json-server
, follow the instructions below to get it up and running.
-
Install JSON Server
If you haven't installed
json-server
globally, you can install it via npm:npm install -g json-server
-
Create db.json File
In your project directory, create a file called
db.json
in the root folder. This file will simulate your backend data. Here’s an example of what it might look like:{ "tasks": [ { "id": 1, "name": "Learn Angular", "createdAt": 0, "done": false }, { "id": 2, "name": "Learn JSON Server", "createdAt": 0, "done": false } ] }
-
Run JSON Server
After creating
db.json
, you can runjson-server
to start the mock backend:json-server --watch db.json --port 3000
This will start the backend API on
http://localhost:3000/
and will automatically create routes for CRUD operations on yourtasks
. -
Enable CORS for the Backend (Optional but recommended)
If you're facing CORS issues (cross-origin resource sharing), you can install and configure
json-server
to handle them:npm install -g json-server json-server --watch db.json --port 3000 --host 0.0.0.0 --cors
This will allow the frontend app to make requests from any origin.
Run ng generate component component-name
to generate a new component. You can also use ng generate directive|pipe|service|class|guard|interface|enum|module
.
Run ng build
to build the project. The build artifacts will be stored in the dist/
directory.
Run ng test
to execute the unit tests via Karma.
Run ng e2e
to execute the end-to-end tests via a platform of your choice. To use this command, you need to first add a package that implements end-to-end testing capabilities.
To get more help on the Angular CLI use ng help
or go check out the Angular CLI Overview and Command Reference page.
- Backend:
json-server
running onhttp://localhost:3000/
to provide API for tasks (GET/tasks
, POST/tasks
, etc.). - Frontend: Angular frontend running on
http://localhost:4200/
that communicates with thejson-server
API.
GET /tasks
POST /tasks
Request Body:
{
"name": "New Task",
"done": false
}
PUT /tasks/:id
Request Body:
{
"id": 1,
"name": "Updated Task",
"done": true
}
DELETE /tasks/:id
curl http://localhost:3000/tasks
curl -X POST -H "Content-Type: application/json" -d '{"name": "New Task", "done": false}' http://localhost:3000/tasks
curl -X PUT -H "Content-Type: application/json" -d '{"id": 1, "name": "Updated Task", "done": true}' http://localhost:3000/tasks/1
curl -X DELETE http://localhost:3000/tasks/1