NodeJS Performance - Multiple routes vs Single routes
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I have created a single endpoint in Node.js.
Following is the end-point:
app.post('/processMyRequests',function(req,res){
switch(req.body.functionality) {
case "functionalityName1":
jsFileName1.functionA(req,res);
break;
case "functionalityName2":
jsFileName2.functionB(req,res);
break;
default:
res.send("Sorry for that");
break;
}
});
In each of these functions, calls to APIs are done, then the data is processed, and finally response is sent back.
My questions:
- Since Node.js as a default handles requests asynchronously, can we have a single route for all the responses?
- Will concurrency be an issue i.e. when parallel hits are happening into the single route will Node.js stall or slow down?
- If the answer to question (2) is YES, how will it change when I have separate routes i.e if the same amount of requests come into a specific route then it is going to be the same issue right?
Would be happy if someone could share real-time use cases. Thanks
node.js concurrency
add a comment |
I have created a single endpoint in Node.js.
Following is the end-point:
app.post('/processMyRequests',function(req,res){
switch(req.body.functionality) {
case "functionalityName1":
jsFileName1.functionA(req,res);
break;
case "functionalityName2":
jsFileName2.functionB(req,res);
break;
default:
res.send("Sorry for that");
break;
}
});
In each of these functions, calls to APIs are done, then the data is processed, and finally response is sent back.
My questions:
- Since Node.js as a default handles requests asynchronously, can we have a single route for all the responses?
- Will concurrency be an issue i.e. when parallel hits are happening into the single route will Node.js stall or slow down?
- If the answer to question (2) is YES, how will it change when I have separate routes i.e if the same amount of requests come into a specific route then it is going to be the same issue right?
Would be happy if someone could share real-time use cases. Thanks
node.js concurrency
add a comment |
I have created a single endpoint in Node.js.
Following is the end-point:
app.post('/processMyRequests',function(req,res){
switch(req.body.functionality) {
case "functionalityName1":
jsFileName1.functionA(req,res);
break;
case "functionalityName2":
jsFileName2.functionB(req,res);
break;
default:
res.send("Sorry for that");
break;
}
});
In each of these functions, calls to APIs are done, then the data is processed, and finally response is sent back.
My questions:
- Since Node.js as a default handles requests asynchronously, can we have a single route for all the responses?
- Will concurrency be an issue i.e. when parallel hits are happening into the single route will Node.js stall or slow down?
- If the answer to question (2) is YES, how will it change when I have separate routes i.e if the same amount of requests come into a specific route then it is going to be the same issue right?
Would be happy if someone could share real-time use cases. Thanks
node.js concurrency
I have created a single endpoint in Node.js.
Following is the end-point:
app.post('/processMyRequests',function(req,res){
switch(req.body.functionality) {
case "functionalityName1":
jsFileName1.functionA(req,res);
break;
case "functionalityName2":
jsFileName2.functionB(req,res);
break;
default:
res.send("Sorry for that");
break;
}
});
In each of these functions, calls to APIs are done, then the data is processed, and finally response is sent back.
My questions:
- Since Node.js as a default handles requests asynchronously, can we have a single route for all the responses?
- Will concurrency be an issue i.e. when parallel hits are happening into the single route will Node.js stall or slow down?
- If the answer to question (2) is YES, how will it change when I have separate routes i.e if the same amount of requests come into a specific route then it is going to be the same issue right?
Would be happy if someone could share real-time use cases. Thanks
node.js concurrency
node.js concurrency
edited Nov 16 '18 at 15:41
Evan Bechtol
2,1931829
2,1931829
asked Nov 16 '18 at 13:59
user5210703user5210703
206
206
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
- You technically can have a single route for all the responses, but it's considered "better-practice" to create endpoints which are compact, clear in what the intended function/purpose is, and not too complex; in your example, there could be many possible branches of code that the route could take. This requires unique logic for each branch, which adds to the complexity of your endpoints, and takes away from the clarity of the code. Imagine that when an error occurs, you now have to debug potentially multiple different files and different branches of your endpoint, when you could have created a separate endpoint for each unique "branch".
- As your application grows in both size, and complexity, you are going to want an easy way to manage your API. Putting lots of stuff into one endpoint is going to be a nightmare for you to maintain, and debug.
- It may be useful for you to look at some tutorials/docs about how to design and implement an API, here is a good article from Scotch.io
Example for question one:
// GET multiple records
app.get('/functionality1',function(req,res){
//Unique logic for functionality
});
// GET a record by an 'id' field
app.get('/functionality1/:id',function(req,res){
//Unique logic for functionality
});
// POST a new record
app.post('/functionality1',function(req,res){
//Unique logic for functionality
});
// PUT (update) a record
app.put('/functionality1',function(req,res){
//Unique logic for functionality
});
// DELETE a record
app.delete('/functionality1',function(req,res){
//Unique logic for functionality
});
app.get('/functionality2',function(req,res){
//Unique logic for functionality
});
...
This gives you a much clearer idea of what is happening for each endpoint, versus having to digest a lot of technically unrelated logic in a single API endpoint. Summing it up, it's better to have endpoints which are clear and concise in their purpose, and scope.
It really depends on how the logic is implemented; obviously Node.js is single-threaded. This means it can only process 1 "stream" of code at a time (no true concurrency or parallelism). However, Node gets around this through its event-loop. The problem that you could see depends on if you wrote asynchronous (non-blocking) code, or synchronous (blocking) code. In Node it's almost always better and recommended to write non-blocking code. This helps to prevent blocking the event loop, meaning your node app can do other things while, for example waiting for a file to finish being read, an API call to finish, or a promise to resolve. Writing blocking code will result in your application bottle-necking/"hanging", which is perceived by your end-users as higher-latency
Having multiple routes, or a single route isn't going to resolve this problem. It's more about how you are utilizing (or not utilizing) the event loop. It's extremely important to use asynchronous code as much as possible.
- One thing that you can do if you absolutely must use synchronous code (this is actually a good approach to leverage regardless of code synchronicity)is to implement a microservice architecture, where a service can process your blocking (or resource-intensive) code off of your API Node service. This frees up your API service to handle requests as rapidly as possible, and leave the heavy lifting to other services.
- Another possibility is to leverage clustering. This gives you the ability to run node as if it were multi-threaded, by spawning "worker" processes, which are identical to your master process, with the difference in that they are able to process work individually. This type of approach is extremely useful if you expect that you will have a very busy API service.
Some extremely helpful resources:
- Node.js Express Best Practices
- A GREAT video explaining the event-loop
- Parallelism vs. Concurrency in Node.js
- Node.js Clustering
- API Design
Thanks, Evan.Such an eye-opener. You were saying for better debugging we need to go with separate routes. As you see we have just the switch-case function and based on which a specific function from a specific JS file is called. So If I log the functionality name before the switch case, I can identify which function was called. Please provide your suggestion.
– user5210703
Nov 19 '18 at 14:52
1
The problem is that the architecture for the API is not great; as your API grows, its Cyclomatic Complexity grows as well. This means that it becomes much more difficult to write and test your code over time. More importantly, your API structure should be intuitive. For example, if I wanted to retrieve user data using your structure I would have to make a POST HTTP req. to'/processMyRequests'
and the body would have say something like "getuser". That doesn't make much sense, when I could make a GET to/user
. It's much more intuitive
– Evan Bechtol
Nov 20 '18 at 19:59
1
You need to make proper use of your HTTP verbs. It doesn't make sense to force every request to include a body object, when it could be a simple GET request, for example. You are increasing the amount of data and overhead required to perform an action that could be done much more simply by just using the correct HTTP verb for the request.
– Evan Bechtol
Nov 20 '18 at 20:01
Got it Evan. Thanks again.
– user5210703
Nov 26 '18 at 11:02
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53339321%2fnodejs-performance-multiple-routes-vs-single-routes%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
- You technically can have a single route for all the responses, but it's considered "better-practice" to create endpoints which are compact, clear in what the intended function/purpose is, and not too complex; in your example, there could be many possible branches of code that the route could take. This requires unique logic for each branch, which adds to the complexity of your endpoints, and takes away from the clarity of the code. Imagine that when an error occurs, you now have to debug potentially multiple different files and different branches of your endpoint, when you could have created a separate endpoint for each unique "branch".
- As your application grows in both size, and complexity, you are going to want an easy way to manage your API. Putting lots of stuff into one endpoint is going to be a nightmare for you to maintain, and debug.
- It may be useful for you to look at some tutorials/docs about how to design and implement an API, here is a good article from Scotch.io
Example for question one:
// GET multiple records
app.get('/functionality1',function(req,res){
//Unique logic for functionality
});
// GET a record by an 'id' field
app.get('/functionality1/:id',function(req,res){
//Unique logic for functionality
});
// POST a new record
app.post('/functionality1',function(req,res){
//Unique logic for functionality
});
// PUT (update) a record
app.put('/functionality1',function(req,res){
//Unique logic for functionality
});
// DELETE a record
app.delete('/functionality1',function(req,res){
//Unique logic for functionality
});
app.get('/functionality2',function(req,res){
//Unique logic for functionality
});
...
This gives you a much clearer idea of what is happening for each endpoint, versus having to digest a lot of technically unrelated logic in a single API endpoint. Summing it up, it's better to have endpoints which are clear and concise in their purpose, and scope.
It really depends on how the logic is implemented; obviously Node.js is single-threaded. This means it can only process 1 "stream" of code at a time (no true concurrency or parallelism). However, Node gets around this through its event-loop. The problem that you could see depends on if you wrote asynchronous (non-blocking) code, or synchronous (blocking) code. In Node it's almost always better and recommended to write non-blocking code. This helps to prevent blocking the event loop, meaning your node app can do other things while, for example waiting for a file to finish being read, an API call to finish, or a promise to resolve. Writing blocking code will result in your application bottle-necking/"hanging", which is perceived by your end-users as higher-latency
Having multiple routes, or a single route isn't going to resolve this problem. It's more about how you are utilizing (or not utilizing) the event loop. It's extremely important to use asynchronous code as much as possible.
- One thing that you can do if you absolutely must use synchronous code (this is actually a good approach to leverage regardless of code synchronicity)is to implement a microservice architecture, where a service can process your blocking (or resource-intensive) code off of your API Node service. This frees up your API service to handle requests as rapidly as possible, and leave the heavy lifting to other services.
- Another possibility is to leverage clustering. This gives you the ability to run node as if it were multi-threaded, by spawning "worker" processes, which are identical to your master process, with the difference in that they are able to process work individually. This type of approach is extremely useful if you expect that you will have a very busy API service.
Some extremely helpful resources:
- Node.js Express Best Practices
- A GREAT video explaining the event-loop
- Parallelism vs. Concurrency in Node.js
- Node.js Clustering
- API Design
Thanks, Evan.Such an eye-opener. You were saying for better debugging we need to go with separate routes. As you see we have just the switch-case function and based on which a specific function from a specific JS file is called. So If I log the functionality name before the switch case, I can identify which function was called. Please provide your suggestion.
– user5210703
Nov 19 '18 at 14:52
1
The problem is that the architecture for the API is not great; as your API grows, its Cyclomatic Complexity grows as well. This means that it becomes much more difficult to write and test your code over time. More importantly, your API structure should be intuitive. For example, if I wanted to retrieve user data using your structure I would have to make a POST HTTP req. to'/processMyRequests'
and the body would have say something like "getuser". That doesn't make much sense, when I could make a GET to/user
. It's much more intuitive
– Evan Bechtol
Nov 20 '18 at 19:59
1
You need to make proper use of your HTTP verbs. It doesn't make sense to force every request to include a body object, when it could be a simple GET request, for example. You are increasing the amount of data and overhead required to perform an action that could be done much more simply by just using the correct HTTP verb for the request.
– Evan Bechtol
Nov 20 '18 at 20:01
Got it Evan. Thanks again.
– user5210703
Nov 26 '18 at 11:02
add a comment |
- You technically can have a single route for all the responses, but it's considered "better-practice" to create endpoints which are compact, clear in what the intended function/purpose is, and not too complex; in your example, there could be many possible branches of code that the route could take. This requires unique logic for each branch, which adds to the complexity of your endpoints, and takes away from the clarity of the code. Imagine that when an error occurs, you now have to debug potentially multiple different files and different branches of your endpoint, when you could have created a separate endpoint for each unique "branch".
- As your application grows in both size, and complexity, you are going to want an easy way to manage your API. Putting lots of stuff into one endpoint is going to be a nightmare for you to maintain, and debug.
- It may be useful for you to look at some tutorials/docs about how to design and implement an API, here is a good article from Scotch.io
Example for question one:
// GET multiple records
app.get('/functionality1',function(req,res){
//Unique logic for functionality
});
// GET a record by an 'id' field
app.get('/functionality1/:id',function(req,res){
//Unique logic for functionality
});
// POST a new record
app.post('/functionality1',function(req,res){
//Unique logic for functionality
});
// PUT (update) a record
app.put('/functionality1',function(req,res){
//Unique logic for functionality
});
// DELETE a record
app.delete('/functionality1',function(req,res){
//Unique logic for functionality
});
app.get('/functionality2',function(req,res){
//Unique logic for functionality
});
...
This gives you a much clearer idea of what is happening for each endpoint, versus having to digest a lot of technically unrelated logic in a single API endpoint. Summing it up, it's better to have endpoints which are clear and concise in their purpose, and scope.
It really depends on how the logic is implemented; obviously Node.js is single-threaded. This means it can only process 1 "stream" of code at a time (no true concurrency or parallelism). However, Node gets around this through its event-loop. The problem that you could see depends on if you wrote asynchronous (non-blocking) code, or synchronous (blocking) code. In Node it's almost always better and recommended to write non-blocking code. This helps to prevent blocking the event loop, meaning your node app can do other things while, for example waiting for a file to finish being read, an API call to finish, or a promise to resolve. Writing blocking code will result in your application bottle-necking/"hanging", which is perceived by your end-users as higher-latency
Having multiple routes, or a single route isn't going to resolve this problem. It's more about how you are utilizing (or not utilizing) the event loop. It's extremely important to use asynchronous code as much as possible.
- One thing that you can do if you absolutely must use synchronous code (this is actually a good approach to leverage regardless of code synchronicity)is to implement a microservice architecture, where a service can process your blocking (or resource-intensive) code off of your API Node service. This frees up your API service to handle requests as rapidly as possible, and leave the heavy lifting to other services.
- Another possibility is to leverage clustering. This gives you the ability to run node as if it were multi-threaded, by spawning "worker" processes, which are identical to your master process, with the difference in that they are able to process work individually. This type of approach is extremely useful if you expect that you will have a very busy API service.
Some extremely helpful resources:
- Node.js Express Best Practices
- A GREAT video explaining the event-loop
- Parallelism vs. Concurrency in Node.js
- Node.js Clustering
- API Design
Thanks, Evan.Such an eye-opener. You were saying for better debugging we need to go with separate routes. As you see we have just the switch-case function and based on which a specific function from a specific JS file is called. So If I log the functionality name before the switch case, I can identify which function was called. Please provide your suggestion.
– user5210703
Nov 19 '18 at 14:52
1
The problem is that the architecture for the API is not great; as your API grows, its Cyclomatic Complexity grows as well. This means that it becomes much more difficult to write and test your code over time. More importantly, your API structure should be intuitive. For example, if I wanted to retrieve user data using your structure I would have to make a POST HTTP req. to'/processMyRequests'
and the body would have say something like "getuser". That doesn't make much sense, when I could make a GET to/user
. It's much more intuitive
– Evan Bechtol
Nov 20 '18 at 19:59
1
You need to make proper use of your HTTP verbs. It doesn't make sense to force every request to include a body object, when it could be a simple GET request, for example. You are increasing the amount of data and overhead required to perform an action that could be done much more simply by just using the correct HTTP verb for the request.
– Evan Bechtol
Nov 20 '18 at 20:01
Got it Evan. Thanks again.
– user5210703
Nov 26 '18 at 11:02
add a comment |
- You technically can have a single route for all the responses, but it's considered "better-practice" to create endpoints which are compact, clear in what the intended function/purpose is, and not too complex; in your example, there could be many possible branches of code that the route could take. This requires unique logic for each branch, which adds to the complexity of your endpoints, and takes away from the clarity of the code. Imagine that when an error occurs, you now have to debug potentially multiple different files and different branches of your endpoint, when you could have created a separate endpoint for each unique "branch".
- As your application grows in both size, and complexity, you are going to want an easy way to manage your API. Putting lots of stuff into one endpoint is going to be a nightmare for you to maintain, and debug.
- It may be useful for you to look at some tutorials/docs about how to design and implement an API, here is a good article from Scotch.io
Example for question one:
// GET multiple records
app.get('/functionality1',function(req,res){
//Unique logic for functionality
});
// GET a record by an 'id' field
app.get('/functionality1/:id',function(req,res){
//Unique logic for functionality
});
// POST a new record
app.post('/functionality1',function(req,res){
//Unique logic for functionality
});
// PUT (update) a record
app.put('/functionality1',function(req,res){
//Unique logic for functionality
});
// DELETE a record
app.delete('/functionality1',function(req,res){
//Unique logic for functionality
});
app.get('/functionality2',function(req,res){
//Unique logic for functionality
});
...
This gives you a much clearer idea of what is happening for each endpoint, versus having to digest a lot of technically unrelated logic in a single API endpoint. Summing it up, it's better to have endpoints which are clear and concise in their purpose, and scope.
It really depends on how the logic is implemented; obviously Node.js is single-threaded. This means it can only process 1 "stream" of code at a time (no true concurrency or parallelism). However, Node gets around this through its event-loop. The problem that you could see depends on if you wrote asynchronous (non-blocking) code, or synchronous (blocking) code. In Node it's almost always better and recommended to write non-blocking code. This helps to prevent blocking the event loop, meaning your node app can do other things while, for example waiting for a file to finish being read, an API call to finish, or a promise to resolve. Writing blocking code will result in your application bottle-necking/"hanging", which is perceived by your end-users as higher-latency
Having multiple routes, or a single route isn't going to resolve this problem. It's more about how you are utilizing (or not utilizing) the event loop. It's extremely important to use asynchronous code as much as possible.
- One thing that you can do if you absolutely must use synchronous code (this is actually a good approach to leverage regardless of code synchronicity)is to implement a microservice architecture, where a service can process your blocking (or resource-intensive) code off of your API Node service. This frees up your API service to handle requests as rapidly as possible, and leave the heavy lifting to other services.
- Another possibility is to leverage clustering. This gives you the ability to run node as if it were multi-threaded, by spawning "worker" processes, which are identical to your master process, with the difference in that they are able to process work individually. This type of approach is extremely useful if you expect that you will have a very busy API service.
Some extremely helpful resources:
- Node.js Express Best Practices
- A GREAT video explaining the event-loop
- Parallelism vs. Concurrency in Node.js
- Node.js Clustering
- API Design
- You technically can have a single route for all the responses, but it's considered "better-practice" to create endpoints which are compact, clear in what the intended function/purpose is, and not too complex; in your example, there could be many possible branches of code that the route could take. This requires unique logic for each branch, which adds to the complexity of your endpoints, and takes away from the clarity of the code. Imagine that when an error occurs, you now have to debug potentially multiple different files and different branches of your endpoint, when you could have created a separate endpoint for each unique "branch".
- As your application grows in both size, and complexity, you are going to want an easy way to manage your API. Putting lots of stuff into one endpoint is going to be a nightmare for you to maintain, and debug.
- It may be useful for you to look at some tutorials/docs about how to design and implement an API, here is a good article from Scotch.io
Example for question one:
// GET multiple records
app.get('/functionality1',function(req,res){
//Unique logic for functionality
});
// GET a record by an 'id' field
app.get('/functionality1/:id',function(req,res){
//Unique logic for functionality
});
// POST a new record
app.post('/functionality1',function(req,res){
//Unique logic for functionality
});
// PUT (update) a record
app.put('/functionality1',function(req,res){
//Unique logic for functionality
});
// DELETE a record
app.delete('/functionality1',function(req,res){
//Unique logic for functionality
});
app.get('/functionality2',function(req,res){
//Unique logic for functionality
});
...
This gives you a much clearer idea of what is happening for each endpoint, versus having to digest a lot of technically unrelated logic in a single API endpoint. Summing it up, it's better to have endpoints which are clear and concise in their purpose, and scope.
It really depends on how the logic is implemented; obviously Node.js is single-threaded. This means it can only process 1 "stream" of code at a time (no true concurrency or parallelism). However, Node gets around this through its event-loop. The problem that you could see depends on if you wrote asynchronous (non-blocking) code, or synchronous (blocking) code. In Node it's almost always better and recommended to write non-blocking code. This helps to prevent blocking the event loop, meaning your node app can do other things while, for example waiting for a file to finish being read, an API call to finish, or a promise to resolve. Writing blocking code will result in your application bottle-necking/"hanging", which is perceived by your end-users as higher-latency
Having multiple routes, or a single route isn't going to resolve this problem. It's more about how you are utilizing (or not utilizing) the event loop. It's extremely important to use asynchronous code as much as possible.
- One thing that you can do if you absolutely must use synchronous code (this is actually a good approach to leverage regardless of code synchronicity)is to implement a microservice architecture, where a service can process your blocking (or resource-intensive) code off of your API Node service. This frees up your API service to handle requests as rapidly as possible, and leave the heavy lifting to other services.
- Another possibility is to leverage clustering. This gives you the ability to run node as if it were multi-threaded, by spawning "worker" processes, which are identical to your master process, with the difference in that they are able to process work individually. This type of approach is extremely useful if you expect that you will have a very busy API service.
Some extremely helpful resources:
- Node.js Express Best Practices
- A GREAT video explaining the event-loop
- Parallelism vs. Concurrency in Node.js
- Node.js Clustering
- API Design
edited Nov 16 '18 at 15:42
answered Nov 16 '18 at 14:31
Evan BechtolEvan Bechtol
2,1931829
2,1931829
Thanks, Evan.Such an eye-opener. You were saying for better debugging we need to go with separate routes. As you see we have just the switch-case function and based on which a specific function from a specific JS file is called. So If I log the functionality name before the switch case, I can identify which function was called. Please provide your suggestion.
– user5210703
Nov 19 '18 at 14:52
1
The problem is that the architecture for the API is not great; as your API grows, its Cyclomatic Complexity grows as well. This means that it becomes much more difficult to write and test your code over time. More importantly, your API structure should be intuitive. For example, if I wanted to retrieve user data using your structure I would have to make a POST HTTP req. to'/processMyRequests'
and the body would have say something like "getuser". That doesn't make much sense, when I could make a GET to/user
. It's much more intuitive
– Evan Bechtol
Nov 20 '18 at 19:59
1
You need to make proper use of your HTTP verbs. It doesn't make sense to force every request to include a body object, when it could be a simple GET request, for example. You are increasing the amount of data and overhead required to perform an action that could be done much more simply by just using the correct HTTP verb for the request.
– Evan Bechtol
Nov 20 '18 at 20:01
Got it Evan. Thanks again.
– user5210703
Nov 26 '18 at 11:02
add a comment |
Thanks, Evan.Such an eye-opener. You were saying for better debugging we need to go with separate routes. As you see we have just the switch-case function and based on which a specific function from a specific JS file is called. So If I log the functionality name before the switch case, I can identify which function was called. Please provide your suggestion.
– user5210703
Nov 19 '18 at 14:52
1
The problem is that the architecture for the API is not great; as your API grows, its Cyclomatic Complexity grows as well. This means that it becomes much more difficult to write and test your code over time. More importantly, your API structure should be intuitive. For example, if I wanted to retrieve user data using your structure I would have to make a POST HTTP req. to'/processMyRequests'
and the body would have say something like "getuser". That doesn't make much sense, when I could make a GET to/user
. It's much more intuitive
– Evan Bechtol
Nov 20 '18 at 19:59
1
You need to make proper use of your HTTP verbs. It doesn't make sense to force every request to include a body object, when it could be a simple GET request, for example. You are increasing the amount of data and overhead required to perform an action that could be done much more simply by just using the correct HTTP verb for the request.
– Evan Bechtol
Nov 20 '18 at 20:01
Got it Evan. Thanks again.
– user5210703
Nov 26 '18 at 11:02
Thanks, Evan.Such an eye-opener. You were saying for better debugging we need to go with separate routes. As you see we have just the switch-case function and based on which a specific function from a specific JS file is called. So If I log the functionality name before the switch case, I can identify which function was called. Please provide your suggestion.
– user5210703
Nov 19 '18 at 14:52
Thanks, Evan.Such an eye-opener. You were saying for better debugging we need to go with separate routes. As you see we have just the switch-case function and based on which a specific function from a specific JS file is called. So If I log the functionality name before the switch case, I can identify which function was called. Please provide your suggestion.
– user5210703
Nov 19 '18 at 14:52
1
1
The problem is that the architecture for the API is not great; as your API grows, its Cyclomatic Complexity grows as well. This means that it becomes much more difficult to write and test your code over time. More importantly, your API structure should be intuitive. For example, if I wanted to retrieve user data using your structure I would have to make a POST HTTP req. to
'/processMyRequests'
and the body would have say something like "getuser". That doesn't make much sense, when I could make a GET to /user
. It's much more intuitive– Evan Bechtol
Nov 20 '18 at 19:59
The problem is that the architecture for the API is not great; as your API grows, its Cyclomatic Complexity grows as well. This means that it becomes much more difficult to write and test your code over time. More importantly, your API structure should be intuitive. For example, if I wanted to retrieve user data using your structure I would have to make a POST HTTP req. to
'/processMyRequests'
and the body would have say something like "getuser". That doesn't make much sense, when I could make a GET to /user
. It's much more intuitive– Evan Bechtol
Nov 20 '18 at 19:59
1
1
You need to make proper use of your HTTP verbs. It doesn't make sense to force every request to include a body object, when it could be a simple GET request, for example. You are increasing the amount of data and overhead required to perform an action that could be done much more simply by just using the correct HTTP verb for the request.
– Evan Bechtol
Nov 20 '18 at 20:01
You need to make proper use of your HTTP verbs. It doesn't make sense to force every request to include a body object, when it could be a simple GET request, for example. You are increasing the amount of data and overhead required to perform an action that could be done much more simply by just using the correct HTTP verb for the request.
– Evan Bechtol
Nov 20 '18 at 20:01
Got it Evan. Thanks again.
– user5210703
Nov 26 '18 at 11:02
Got it Evan. Thanks again.
– user5210703
Nov 26 '18 at 11:02
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53339321%2fnodejs-performance-multiple-routes-vs-single-routes%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown