A small microservice on top of Node.js
Check a live version deployed on the Heroku Cloud Application Platform.
https://feathers-microservice-demo.herokuapp.com/
This project uses Feathers. An open source web framework for building modern real-time applications.
This is the backend for the https://github.com/josepcrespo/nuxt-vuetify-pwa-demo project. It exposes a single API endpoint called favorites
.
Feathers service methods that provide CRUD functionality are:
find
: Find all data (potentially matching a query).get
: Get a single data entry by its unique identifier.create
: Create new data.update
: Update an existing data entry by completely replacing it.patch
: Update one or more data entries by merging with the new data.remove
: Remove one or more existing data entries.
When used as a REST API, incoming requests get mapped automatically to their corresponding service method like this:
Service method | HTTP method | Path |
---|---|---|
service.find({ query: {} }) | GET | /favorites |
service.find({ query: { listName: 'title' } }) | GET | /favorites?listName=title |
service.get(1) | GET | /favorites/1 |
service.create(body) | POST | /favorites |
service.update(1, body) | PUT | /favorites/1 |
service.patch(1, body) | PATCH | /favorites/1 |
service.remove(1) | DELETE | /favorites/1 |
This way, we have a fully functional REST API endpoint for our /favorites
service.
You need Git >= v2.24.3
and, Docker Engine >= v19.03.13
. Make sure you don't have any other service using the 3030 port.
Execute the following single line list of commands on your favorite shell:
$ git clone https://github.com/josepcrespo/feathers-microservice-demo.git && cd feathers-microservice-demo && docker-compose build --no-cache --force-rm && docker-compose up
The service will be available at http://localhost:3030 after the process finishes (it may take a few minutes), you will see something like this:
Getting up and running is as easy as 1, 2, 3 and… 4.
-
Install your dependencies
cd path/to/feathers-microservice-demo npm install
-
Connect your local MySQL instance to the app.
You need to set your MySQL connection string into the /config/default.json file, on the mysql
key.
-
Start your app for development
npm run dev
Simply run npm run test
and all your tests in the test/
directory will be run.
Feathers has a powerful command line interface. Here are a few things it can do:
$ npm install -g @feathersjs/cli # Install Feathers CLI
$ feathers generate service # Generate a new Service
$ feathers generate hook # Generate a new Hook
$ feathers help # Show all commands
For more information on all the things you can do with Feathers visit docs.feathersjs.com.