Generate secure API from your browser

Rest Oct 08, 2019

Generate A Secured node API with authentication and authorization directly from your browser at the same time fully customizable.

For Better Explanation Please watch the video below

Let's get started,

1) First visit to start.smartcodehub.com

2) Login with your credential if you have not register then you can register here.

3) After login download the stater kit and open it with vs code and run

npm i

4) Get back to website and create entities , and create a modal containing password field so that we can use that entity as our authorization service.

So let's say we have created a table user containing fields name , email , password

Now click on create resources and don't click the download button just get back to modal where you can see your all modals.

Now you can see one change that, there is a lock icon why its showing

so the lock icon is used to tell that weather there is a password field or not in the modal and it also indicates that this modal can be use for other table to create a secure resource that means let's we have another table employee

and we don't want it to be open like no one show post or get in this table without login so for that first he/she will register themselves using the user entity and after that when they login , a token will be generated and when we pass that token in header and do post request to employee table t will accept but if we don't add token it will give an error Unauthorized.

5) Now click on lock icon and select what you want to pass and what you want to get from payload.

6) Generating the user resource copy the content of zip file in vs code accordingly , now open the user.instruction.txt and do the following changes.

7) In employee table , click on info icon you will see checkbox saying create secure resource just check it and choose the table from which you want authenticate.

8) Click on generate API resources , download and extract the zip and copy the content accordingly into vs code , now open the employee.instruction.txt and do the following changes.

9) Now, let's check the API working run the

npm start

command in vs code terminal and your api will run on localhost copy the localhost url and paste it in postman.

10) Let's first register  a user using post request in

https://localhost:3331/api/user

and in body > raw select json format

{
"name":"username",
"email":"email@mail.com",
"password":"password"
}

and post it,Your Output should be this,

Now in url add /login

and remove name field from body and send request

then it will generate a token

Now , open new tab and copy the api url and add /employee and choose post method and click on send button there you will get error for that you need to do change in

employee.route.js

const ENV_SECRET_STRING = "The_String_Present_In_Your_userController";

Copy the string from userController.js

 const ENV_SECRET_STRING = "Put_A_Secure_string_here_for_token_generation";
  

Now again post it you will see unauthorize

that means user is login but token is not passed in header.

so for that just copy the token from user api and add it to header of employee api and post it you will see empty object.

That's it we have successfully generated secure API.

if you like it do support us on  product hunt by upvoting here

Neeraj Dana

Experienced Software Engineer with a demonstrated history of working in the information technology and services industry. Skilled in Angular, React, React-Native, Vue js, Machine Learning