Service
In this guide, we'll go through the steps to create a new service in your SoapJS project. You can create services using CLI commands, interactive forms, or by defining them in a JSON file.
In SoapJS projects, services operates similarly to a repository, utilizing IoC (Inversion of Control) principles. In the business logic, we refer to the WeatherService
interface rather than a specific implementation, ensuring decoupling and flexibility. The actual service bound to this interface, such as WeatherServiceImpl
, is determined within the Dependencies
configuration, allowing for easy substitution and testing.
Creating new service
Using CLI Command with options
To create a new service directly via the CLI, use the following command:
Options explained:
-n
: Name of the service (e.g., "Weather").-e
: Endpoint associated with the service (e.g., "weather").-m
: Method name(s)/ declaration(s), separated by commas.-w
: Generate with dependencies included.-f
: Force the creation, overwrite files if necessary.--help
: display help for command
Using Interactive Form
If you prefer to use an interactive form to specify your service details, simply run:
Follow the prompts to enter your service's details.
Using JSON Configuration
Alternatively, you can define your services in a JSON file. Here is an example structure:
Save this to a file, for example api.json
, and run:
Options:
--json
: Path to your JSON configuration file.--no-tests
: Skip test generation.--no-rel
: Skip generating related files. You can also specify specific groups.--force
: Force the creation, overwrite files if necessary.--patch
: Add content to the files if they exists.
File Structure
After creating your service, your file structure (assuming default configuration settings) should look like this:
Last updated