Comments (3)
Hi @kchurikov , As per normal scenario your thought is right, but while developing APIs we need to keep our responses consistent.
if(books.length > 0){
return apiResponse.successResponseWithData(res, "Operation success", books);
}else{
return apiResponse.successResponseWithData(res, "Operation success", {});
}
Here books
returns object
when got data, and returns null
in case not. Which makes response inconsistent. That's why I am returning a blank object {}
in else condition. Due to this, API consumer don't need to check for null
and he/she stays Happy 😆 .
I hope your doubts got clear. Closing the issue.
from rest-api-nodejs-mongodb.
I do not argue about the logic. It is about the code stile.
instead of
if (condition) { return a; } else { return b; }
You can just write
if (condition) { return a; } return b;
from rest-api-nodejs-mongodb.
I see, Sure. I will minify conditions from the next update. Thanks for the suggestions & your interest in the repo.
from rest-api-nodejs-mongodb.
Related Issues (17)
- howto call self api? HOT 2
- add docker support HOT 3
- add Kubernetes support
- node-rest-api-mongo
- endpoints? HOT 1
- [Suggestion] HOT 1
- Internal APIs not working
- There is no Logout endpoint
- Getting error Error: Cannot find module 'bcrypt' HOT 4
- Form Data
- Does not work with Google SMTP HOT 1
- "useFindAndModify" is not a valid option to set and algorithms should be set error after updating some packages
- RPC instead of REST
- Starting out for beginners HOT 1
- Refactor If Statements. HOT 1
- Cannot post array HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rest-api-nodejs-mongodb.