SuperApiBoost is a client who seeks to improve development times.
In this post I will show you how to make a complete api under NodeJs with Typescript, Mongo and Express with just two commands an a file.
First thing they need to do is install the client with npm.
npm i -g superapiboost
To generate the project you must execute the "new" command with the -n flag to assign the name
sabo new -n=Awesome
This will create a root folder with the name of the project and install the dependencies.
📦Awesome
┣ 📂node_modules
┣ 📂src
┃ ┣ 📂api
┃ ┃ ┣ 📂routes
┃ ┃ ┗ 📜index.ts
┃ ┣ 📂controllers
┃ ┃ ┗ 📜mongoBasic.ts #CRUD Methods
┃ ┣ 📂interfaces
┃ ┣ 📂tools #utils functions
┃ ┃ ┗ 📜validateType.ts
┃ ┣ 📜app.ts
┃ ┣ 📜config.ts
┃ ┗ 📜mongo.ts
As an example we will create a crud for the following json.
{
"name":"Andy",
"cellphone":303030303,
"isValid":false
}
We will create a json file and use the following format for the generation of the routes and the controller.
{
"name":{
"type":"string",
"required":true,
"default":"'Andy'"
},
"cellphone":{
"type":"number",
"required":false
},
"isValid":{
"type":"boolean",
"required":true,
"default":"true"
}
}
as a key we will assign the name of the property to create.
type: string, number, date, [].
required: false, true.
default(optional): 'true','"Name"'.
We will copy the complete path and execute the generate command.
sabo generate -n=user -p=c:/models/user.json
This will create the interface, controller and routes.
Go to the config.ts file and assign the connection string of our mongo database.
Execute npm start and we will be able to consume the api with our preferred client.
Top comments (0)