File tree Expand file tree Collapse file tree 6 files changed +42
-5
lines changed Expand file tree Collapse file tree 6 files changed +42
-5
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ const express = require("express");
44const client = require ( "./client" ) ;
55
66const path = require ( "path" ) ;
7+ const { employees } = require ( "./dummyEmp" ) ;
78
89const app = express ( ) ;
910
@@ -17,6 +18,25 @@ app.use(
1718 } )
1819) ;
1920
21+ app . post ( "/insert" , ( req , res ) => {
22+ client . insert (
23+ {
24+ email : req . body . email ,
25+ firstName : req . body . firstName ,
26+ lastName : req . body . lastName ,
27+ } ,
28+ ( err , response ) => {
29+ if ( ! err ) {
30+ console . log ( "Success" ) ;
31+ res . redirect ( "/" ) ;
32+ console . log ( response ) ;
33+ } else {
34+ console . log ( err . details ) ;
35+ }
36+ }
37+ ) ;
38+ } ) ;
39+
2040app . get ( "/" , ( req , res ) => {
2141 // Getting getAll function from the client
2242 client . getAll ( { } , ( err , response ) => {
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ package employee;
1010service Employee {
1111 rpc getDetails (EmployeeRequest ) returns (EmployeeResponse ) {}
1212 rpc getAll (Empty ) returns (EmployeeRepeatedResponse ) {}
13+ rpc insert (EmployeeDetails ) returns (EmployeeResponse ) {}
1314}
1415
1516// used to indicate that there is no request to be sent
Original file line number Diff line number Diff line change @@ -34,6 +34,13 @@ function getDetails(call, callback) {
3434 } ) ;
3535}
3636
37+ function insert ( call , callback ) {
38+ let newrecord = call . request ;
39+ newrecord . id = 4 ;
40+ employees . push ( newrecord ) ;
41+ callback ( null , { message : newrecord } ) ;
42+ }
43+
3744function getAll ( call , callback ) {
3845 callback ( null , {
3946 message : employees ,
@@ -49,6 +56,7 @@ function main() {
4956 server . addService ( employeeProto . Employee . service , {
5057 getDetails : getDetails ,
5158 getAll : getAll ,
59+ insert : insert ,
5260 } ) ;
5361
5462 server . bind ( "0.0.0.0:3001" , grpc . ServerCredentials . createInsecure ( ) ) ; // Binds to a port -- createInsecure() is given to say there is no authentication in the server
Original file line number Diff line number Diff line change 1+ POST http://localhost:3000/insert
2+ Content-Type: application/json
3+
4+ {
5+ "email" : " test@test.com" ,
6+ "firstName" : " Dovah" ,
7+ "lastName" : " kiin"
8+ }
Original file line number Diff line number Diff line change @@ -12,8 +12,8 @@ html(lang="en")
1212 th last Name
1313 tr
1414 td
15- fname = details .firstName
15+ email = details .email
1616 td
17- lname = details .lastName
17+ fname = details .firstName
1818 td
19- email = details .email
19+ lname = details .lastName
Original file line number Diff line number Diff line change @@ -12,10 +12,10 @@ html(lang="en")
1212 th last Name
1313 each val in details
1414 tr
15+ td
16+ email= val .email
1517 td
1618 fname= val .firstName
1719 td
1820 lname= val .lastName
19- td
20- email= val .email
2121
You can’t perform that action at this time.
0 commit comments