We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@typicode Please help me with the below problem. Thanks in adv.
//db1.json [ { "id": "Watson", "userId": "Watson", "basicDetails": { "firstName": "Emma", "lastName": "Watson" }, "entitlementDetails": { "defaultEntity": "E1", "defaultEntityName": "United Kingdom", "roles": [ { "roleId": "A1", "description": "Branch Manger" } ], "additionalEntities": [ { "entityId": "E2", "branchId": "102" } ] } } ]
//db2.json [ { "id": "001", "partyID": "001", "basicDetails": { "branchCode": 99, "addressDetails": [ { "addressType": "3" } ], "contactDetails": [ { "contactMethod": "SMS" } ] }, "personalDetails": { "firstName": "ABC", "lastName": "XYZ" } } ]
//to watch multiple json files i created a map.js file //map.js
module.exports = function() { return { user1: require('./db1.json'), user2: require('./db2.json') } }
//run json server using below command json-server map.js
//the below one is working fine. http://localhost:3000/user1/{userId} - Get details of the user identified by the passed user identifier
//not working EXPECTED RESULT: http://localhost:3000/user1/entities/{entityId} - Get details of the users belonging to a particular entity
http://localhost:3000/user1/branches/{branchId} - Get details of the users belonging to a particular branch
ACTUAL RESULT The server responded with a status of 404 (Not Found)
The text was updated successfully, but these errors were encountered:
Hi, I was trying to accomplish the same thing today, I managed to create a solution by adding prefixes to the routes of each file
db.js
const mocks = ["route1", "route2"]; module.exports = () => { const exp = {}; mocks.forEach(m => { const db = require('./' + m + '.json'); Object.keys(db).forEach(d => { exp[m + "_" + d] = db[d]; }); }); return exp; };
routes.json
{ "/route1/*": "/route1_$1", "/route2/*": "/route2_$1" }
and then run json-server --watch ./db.js --routes ./routes.json
json-server --watch ./db.js --routes ./routes.json
Sorry, something went wrong.
No branches or pull requests
@typicode Please help me with the below problem. Thanks in adv.
//db1.json
[
{
"id": "Watson",
"userId": "Watson",
"basicDetails": {
"firstName": "Emma",
"lastName": "Watson"
},
"entitlementDetails": {
"defaultEntity": "E1",
"defaultEntityName": "United Kingdom",
"roles": [
{
"roleId": "A1",
"description": "Branch Manger"
}
],
"additionalEntities": [
{
"entityId": "E2",
"branchId": "102" }
]
}
}
]
//db2.json
[
{
"id": "001",
"partyID": "001",
"basicDetails": {
"branchCode": 99,
"addressDetails": [
{
"addressType": "3"
}
],
"contactDetails": [
{
"contactMethod": "SMS"
}
]
},
"personalDetails": {
"firstName": "ABC",
"lastName": "XYZ"
}
}
]
//to watch multiple json files i created a map.js file
//map.js
module.exports = function() {
return {
user1: require('./db1.json'),
user2: require('./db2.json')
}
}
//run json server using below command
json-server map.js
//the below one is working fine.
http://localhost:3000/user1/{userId} - Get details of the user identified by the passed user identifier
//not working
EXPECTED RESULT:
http://localhost:3000/user1/entities/{entityId} - Get details of the users belonging to a particular entity
http://localhost:3000/user1/branches/{branchId} - Get details of the users belonging to a particular branch
ACTUAL RESULT
The server responded with a status of 404 (Not Found)
The text was updated successfully, but these errors were encountered: