Full-stack Workshop
This is the example code used to teach basic REST API development and how to consume them in a client application.
Goal
To introduce HTTP REST API development principles using a Node.js server and front end to consume the API.
How to Run
First the dependencies must be installed.
npm install
# or with Yarn
yarn
Server
To start the server use the following commands. When changes are made to the server code it should automatically restart. See the console output for errors or other notices.
npm run start:server
# Yarn
yarn start:server
Client
When the client is ran it uses a development only node server
(webpack-dev-server
). Like
the server it reloads the code when it changes and either refreshes the page or
hot loads the new code live. All of the static assets are served directly from
memory and no actual build files are saved to disk.
npm run start:client
# Yarn
yarn start:client
Running the Tests
There are tests for both the client and server. To run them use the following
commands. Note that they are similar to the start
commands.
npm run test:server
npm run test:client
# Yarn
yarn test:server
yarn test:client
The tests are ran using the AVA test runner.
Notes
Postman
Included is a Postman collection. This will help working with the API to test the REST endpoints. Just import the included collection into the Postman app.
Tools and Frameworks
- Node.js
- npm (package manager, you can also use Yarn)
- ESLint (code style and linting)
- Webpack (creates a client bundle, aka "the build")
- React.js (UI component library)
- BabelJS (transforms JS to support new syntaxes)
- FreezerJS (holds UI state)
- KOA (version 2, aka 'next'; the server library)
- LokiJS (lightweight database with MongoDB query interface)
- AVA (test runner)
- SuperTest (sends test requests to the server, based on SuperAgent)
Required Documentation
- KOA Router API
- LokiJS Collection API
- LokiJS Query Examples
- ReactJS Docs
- FreezerJS Docs
- Native Fetch API
Helpful Resources
REST Methods: http://www.restapitutorial.com/lessons/httpmethods.html