Directory Structure

In the previous chapter, we have discussed that there 2 folders needed for Mock JSON response for a successful startup.

The directory structure of your project should be:

backend-mock
|
|- index.js
|- functions
|- data

functions folder will store the JS files will have logical statements that would define routing and response of a request.

data folder will contain the json files will be mapped from the response object in the functions folder.

A Complete example:

functions/shoppingCart.js
module.exports = {
    logic: function ({ headers }, { data }) {
        // logic to manipulate data
    },
    request: {
        method: "GET",
        urlPath: "/mock/list"
    },
    response: {
        status: 200,
        bodyFileName: "cart.json"
    }
};
cart.json
{
    "items": [
        "Apples",
        "Bread"
    ]
}

Above example, will send data present in cart.json when GET localhost:3000/mock/list is hit.

A detailed description of the field in request and response are given in upcoming chapters!

Last updated

Was this helpful?