Well the problem is the following:
I'm developing a frontend app (using vue.js), I've to look for a mock backend (I must not mock it on the front).
In this app I can make http requests, just GET and PATCH are in my interest, I want to make these requests to a mock server (json:api compliant, meaning it returns the correct content-type header as application/vnd.api+json).
This server has to respond with a predefined (already hardcoded) json response, so the only thing I care about the server is that it looks at the url in the request and responds with an existing json file or object.
I've seen some solutions but not one where I can configure a url to be received as follows (I just care about that if method and url match, I return a json file), ex:
and then I respond with a hardcoded json file
Same with a Patch, I don't actually care about analyzing the body, just use the url match to provide the correct predefined response, this one did't pose problems as the url is much more simple and the solutions I found support this type of url:
PATCH http://localhost:PORTNUMBER/api/projects/500
Is there any solution where I can configure my endpoints as the url for the GET request? The ones I found throw me an incorrect path error due to the ?include... part of the url, as they serve only things as PATH/PATH/RESOURCE but when it comes to PATH/PATH/RESOURCE?any-weird-url-I-need then it causes a problem, so far I just need something "as simple" as that.
I tried this by my own using node.js:
// app.js, my main file
var express = require("express");
var bodyParser = require("body-parser");
var app = express();
// configuring the body parser to accept JSON as well as url encoded values
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json({
type: ['application/json', 'application/vnd.api+json']
}));
var routes = require("./routes/routes.js")(app);
var server = app.listen(3000, function () {
console.log("Listening on port %s...", server.address().port);
});
In the routes I define it:
// inside /routes/routes.js
var appRouter = function(app) {
// only works if I let it like "api/projects/1000"
app.get("api/projects/1000?include=subtree,subtree.vertices,vertices", function(req, res) {
res.set('Content-Type', 'application/vnd.api+json');
res.send({-----here goes my json response-----});
});
}
module.exports = appRouter;
Managed to do it, then instead of what I had in app.get, I used:
app.get("api/projects/1000", function(req, res) {
res.set('Content-Type', 'application/vnd.api+json');
if(!req.query.include){
res.send(---whatever response when the url doesn't have include---)
return;
}
res.send({-----here goes my json response when it has include-----});
});
Maybe not the nicest thing in the world but from here you can set it to send previously written json files or anything you need, adjusted exactly for your needs, if anyone has a suggestion as a best response, feel free to comment :)