@@ -210,6 +210,50 @@ And it's just 56ms for all 3 requests! Second and third requests were executed i
210210
211211This is pretty decent, we think!
212212
213+ ## Examples
214+
215+ ### Example 1: Single, simple microservice
216+
217+ Let's say we have a very simple setup: API Gateway + one microservice behind it.
218+
219+ First, we need to let the gateway know about this microservice by adding it to GATEWAY_SERVICES environment variable.
220+
221+ ``` json
222+ {
223+ "service" : []
224+ }
225+ ```
226+
227+ Where * service* is the nickname we chose for our microservice. The array is empty because we will rely on default settings.
228+ Our service has a valid Swagger documentation endpoint running on ``` api/doc ``` URL.
229+
230+ Next, we provide global settings on GATEWAY_GLOBAL environment variable:
231+
232+ ``` json
233+ {
234+ "prefix" : " /v1" ,
235+ "timeout" : 3.0 ,
236+ "doc_point" : " /api/doc" ,
237+ "domain" : " supercompany.io"
238+ }
239+ ```
240+
241+ This tells the gateway that services that don't have explicit URLs provided, will be communicated at
242+ {serviceId}.{domain}, therefore our service will be contacted at service.supercompany.io, request timeout will be 3 seconds,
243+ Swagger documentation will be loaded from ``` /api/doc ``` and all routes will be prefixed with "v1".
244+
245+ We could however specify service's hostname explicitly using "hostname" key in the GATEWAY_SERVICES array.
246+
247+ Now we can run ``` php artisan gateway:parse ``` to force Vrata to parse Swagger documentation
248+ provided by this service. All documented routes will be exposed in this API gateway.
249+
250+ If you use our Docker image, this command will be executed every time you start a container.
251+
252+ Now, if your service had a route ``` GET http://service.supercompany.io/users ``` , it will be available as
253+ ``` GET http://api-gateway.supercompany.io/v1/users ``` and all requests will be subject to JSON Web Token check and rate limiting.
254+
255+ Don't forget to set PRIVATE_KEY and PUBLIC_KEY environment variables, they are necessary for authentication to work.
256+
213257## License
214258
215259The MIT License (MIT)
0 commit comments