Using a Repository
In this guide we will add a new service to manage a list of locations. We will use a datatype repository to specify the service datatype schema.
Adding a Repositopry
Before we can use a repository we need to add the repository to the local Blackbox project. There are two ways of doing this: Load from a file or download from a web address. We will load from a URL.
bb add repository -u http://bb.ellipsistechnology.com/examples-datatypes.json
This will add the repository to the blackbox.json
configuration file
ready for use.
The datatype schemas stored in this file can now be added to the Blackbox project.
If you have the file locally rather than at a URL you can replace the -u
option with -f
as follows:
bb add repository -f examples-datatypes.json
Adding a Datatype from a Repository
To add a datatype from the repository we can simply use the following command
bb add datatype -n location
You should see the following output:
Added datatype coordinates to openapi.json from repository.
Added datatype location to openapi.json from repository.
If you only want to use the repository once, you can add a datatype directly from a local
file as follows:
bb add datatype -n location -f examples-datatypes.json
The datatype should now be in your openapi.json
file ready to be used
by a service in the same way we've done in previous guides.
Add a new location service as follows:
bb add service -n location -d location
Which should guve the following output:
Added path /location
Added datatype coordinates to openapi.json from repository.
Added datatype location to openapi.json from repository.
Set get schema for path /location
Added post to path /location
Addded service to path /location/{name}
Added put to path /location/{name}
Added patch to path /location/{name}
Added delete to path /location/{name}
Successfully added service location
Notice that all HTTP methods have been included in the path updates.
This is the default behaviour if the -m
option is not used.
Having the post, put, patch and delete options will allow us to create,
update and delete locations.
We will now create out service using the same generate operations that we have used in the previous guides:
bb generate datatype && bb generate service && bb generate server
In the next guide we will use a database to store the location data managed by this new service.