To Introduction

Microservice Facade

Step 8. Manual testing of facade

Once all of the system’s microservices are up and running, we can perform some manual testing of the facade we’ve created, to ensure that everything’s working as intended.

First, let’s create a few users without any additional privileges. This can be done with the following command:

curl -X POST -H "Content-Type: application/json" -d "{\"name\": \"User1\",\"login\": \"\",\"email\": \"\",\"language\": \"en\",\"theme\": \"light\",\"time_zone\": \"\",\"password\": \"12345678\"}" http://localhost:8080/api/v1/users/signup
{ "user_id": "cc5eaa9bee154197a75e041568ba94b5",  "user_name": "User1",  "active": true,  "open_time": "2020-07-02T16:38:40.598Z",  "request_time": "2020-07-02T16:38:40.598Z",  "address": "",  "client": "insomnia/2020.2.2",  "user": { "id": "cc5eaa9bee154197a75e041568ba94b5",    "name": "User1",    "login":",    "create_time": "2020-07-02T16:38:39.746Z",  "time_zone": "",  "language": "en",  "theme": "light", "roles":[]}, "data": null, "id": "447f718dbb884bcd965508fe5ffa82d9" }
curl -X POST -H "Content-Type: application/json" -d "{\"name\": \"John Doe\",\"login\": \"\",\"email\": \"\",\"language\": \"en\",\"theme\": \"light\",\"time_zone\": \"\",\"password\": \"12345678\"}" http://localhost:8080/api/v1/users/signup
{"user_id":"2fd0e283c1914daa82611d99fb01ad02","user_name":"John Doe","active":true,"open_time":"2020-07-02T16:45:11.244Z","request_time":"2020-07-02T16:45:11.244Z","address":"","client":"curl/7.55.1","user":{"id":"2fd0e283c1914daa82611d99fb01ad02","name":"John Doe","login":"","create_time":"2020-07-02T16:45:11.223Z","time_zone":"","language":"en","theme":"light","roles":[]},"data":null,"id":"332f300aa63f4da38dd85ef1b25829a6"}

As a result of this operation, we should receive the same data structure in the response as the one we defined in our SessionUserV1 class. The parameter that’s of most importance to us right now is the session ID - the value of the last id field.

Login as User1 to receive access to the Beacons microservice’s methods. This can be done with the following command:

curl -X POST -H "Content-Type: application/json" -d "{\"login\": \"\", \"password\":\"12345678\"}" http://localhost:8080/api/v1/users/signin

For future operations, use the session id that was returned:


Let’s test how our business logic works. Make a request to get all of the Beacons currently in the system using the session ID we mentioned above. You can do this using the following command:

curl -X GET -H "x-session-id:d0b61d48461f41bc8a2bd8b1bf2d6a2e" http://localhost:8080/api/v1/beacons

We receive an empty list as a result, since we haven’t created any Beacons yet in the system.

Attempting to request the URL without a valid session will result in an authentication error:

curl -X GET http://localhost:8080/api/1.0/beacons
{"code":"NOT_SIGNED","status":401,"name":"NOT_SIGNED","message":"User must be signed in to perform this operation","stack":"NOT_SIGNED: User must be signed in to perform this operation ...

Feel free to explore the rest of the system’s functionality on your own using the routes we registered in the facade’s service and the sample data from the Data microservice tutorial.

Congratulations! Having completed all of the steps of this tutorial, you’ve created your first full-fledged facade and are now capable of creating your own using the Pip.Services Toolkit!

This example’s source code is available in our repository on GitHub