Creating a new Service in a FeathersJS app | FeathersJS Series | Part - 3
Services in FeathersJS are used for -
- Reading and/or Writing from Databases.
- Calling another API
- Calling other services like, sending a mail or processing a payment, etc.
For reading and writing from a database, we have service methods that allow us to perform CRUD operations in the database. The various service methods available to us are -
- FIND - Used to retrieve all of the data
- GET - Used to retrieve only specific entries
- CREATE - Used to create new data
- UPDATE - Used to update existing data by completely replacing all of it
- PATCH - Used to update existing data by only replacing the required columns or attributes
- REMOVE - Used to delete one or more existing entries
Creating a new Service
feathers generate service
The above command will generally create a service.js file, models.js file and a hooks.js file.
Models are where we define our database schema and the relationships between two different models.
When a new service is created, by default the models.js file will have a default model with just one attribute or column, named 'text'.
Hooks is where we write middleware functions, which can be invoked before or after or when an error occurs when calling an API.
In Part - 4 of the series, we shall see how to create & define a database schema as models in our service. So stay tuned, keep reading, and let me know what you think about the above article in the comment section below.