The generated scaffolding can be quickly used make calls to external APIs
meaning another endpoint either within your system developed by another team or
a public endpoint of 3rd party provider e.g.
The backend (and frontend) uses the axios library as the HTTP Client.
It is on purpose left as a thin wrapper implementation so that the user can
extend with additional parameters on top of the mandated ones;
e.g. a header for authentication. As such it only returns an unopinionated axios
Instance and not a method initialized implementation. the method parameter is
mainly used as a type guard.
Sample implementation of an entire API can be found in the
../src/ssr/constants/apis/menu.ts, this demonstrates a business
specific implementation of talking to a data provider from node and exposing an
internal route within express for the FE to use for proxy.
The base implementation shouldn't be need to touch and it can be found in the
To extend and add more of your own custom implementation use menu as an example.
baseURL and internalBasePath are rigged to be populated from the config object see below
These are used by the front end hit the relevant proxied endpoint within node (behind an express route).
An example of how this is implemented can be seen in the
../src/ssr/server/index.ts - again this file can be zero-touch and
user should focus only on extending the individual APIs - see
Sample implementation from a page can be seen in
Key things to note:
import api from "constants/apis/menu";
- multiple APIs from constants can be instantiated
import menuApi from "constants/apis/menu";
import categoryApi from "constants/apis/menu";
The application can use a mixture of environment variables and statically defined values. Typically you would define an environment variable for things that are likely to change on stage by stage basis - where stage is Dev, Test, Prod commonly separated by a namespace in the cluster.
At application start a config object is created and used at runtime by various
classes that need to access it, the app code should not reference the
process.env.* at any point instead creating a binding of these values in the
environment-variables.ts which are added into the final config object.
internalBasePath within the
Api subclassing should always
point to a config value e.g. see snippet below