HTTP Method | API Endpoint | Description | Body |
---|---|---|---|
GET | /links |
Get a list of all links. | |
GET | /links |
Get a paginated list of all links. | |
GET | /links/<link_id> |
Get a single link. | |
POST | /links |
Create a new link | url (required), tags (required), description (optional), name (required) |
PUT | /links/<link_id> |
Update a link | url (required), tags (required), description (optional), name (required) |
DELETE | /links/<link_id> |
Delete a link |
- Validation and Error Handling: Implement validation for input parameters and clear error messages.
- Search and Filtering: Add support for searching and filtering in the
GET /links
endpoint. - Versioning: Consider versioning for future changes.
- Run the command to install the typescript package
npm install typescript --save-dev
- Run the command to initialize tsconfig.json - this file will contain your typescript settings more like typescript rules you want to allow/disallow for your project.
tsc --init
- Update the tsconfig.json file: specify the folder it will go to find the .ts file and tell it to exclude node_modules folder
"include": ["src/**/*"],
"exclude": ["node_modules"]
- Update the tsconfig.json file: Also specify the outDir value. Make sure to add
build
folder to gitignore
{
...
"outDir": "build",/* Specify an output folder for all emitted files. */
...
}
- Install ts-node - allow node to use typescript
npm install -D ts-node
npm install -D tslib @types/node
- First install
nodemon
npm install -D nodemon
- Update the script
"scripts": {
...
"start": "npm run build && node build/index.js",
"dev": "nodemon --exec ts-node src/index.ts",
"build": "tsc"
...
},
-
typescript - to make our javascript typed
-
ts-node - to run node with typescript
-
nodemon - for hot reloading
- express
- mysql2 - MySQL client for Node.js
- body-parser - Node.js body parsing middleware.
- dotenv - loads environment variables from a .env file into process.env
- cors - to enable CORS