This project takes an example of an Employee object having four attributes id, name, department, and isActive. We will proceed with adding an employee object in our DB and then performing further operations.
No dependency required. Just install Deno using
curl -fsSL https://deno.land/x/install/install.sh | shand set up your
DENO_INSTALL path in
server.ts is the main configuration file where all the configuration combines such as route definitions, port, and even logging component.
Define your models here for persisting in the database. Here we have created an Employee model in
Define your SQL Connection and Create table script here.
Define your business logic here and it also acts as a midpoint between database and controller layer.
Controller Layer (employeeController.ts):
To perform CRUD operations using HTTP methods(GET,POST,PUT,DELETE).
Define the endpoints in an application and connects to the HTTP methods in a controller.
Running the Application
Run your application by the following command:
deno run --allow-env --allow-net server.ts
The application will come up at base URL
Test your application by appending the endpoints to base URL, PLease find the postman snapshot below:
Create an Employee:
Get Employees List:
Update Employee by Id:
Get Employee By Id:
Delete Employee By Id:
In this tutorial, we learned how to build a CRUD REST-API using Deno js. The complete project can be found at my Github repository: https://github.com/dheerajgupta217/getting-started-with-deno