github.com/hellofresh/janus@v0.0.0-20230925145208-ce8de8183c67/docs/quick_start/add_endpoint.md (about) 1 # Add an endpoint 2 3 The main feature of an API Gateway is to proxy requests to different services, so let's do this. 4 5 ## 1. Adding a new endpoint 6 7 Now that you are authenticated, you can send a request to `/apis` to create a proxy. 8 9 Create an `example.json` file containing your endpoint configuration: 10 11 ```json 12 { 13 "name" : "my-endpoint", 14 "active" : true, 15 "proxy" : { 16 "listen_path" : "/example/*", 17 "upstreams" : { 18 "balancing": "roundrobin", 19 "targets": [ 20 {"target": "http://www.mocky.io/v2/595625d22900008702cd71e8"} 21 ] 22 }, 23 "methods" : ["GET"] 24 } 25 } 26 ``` 27 28 And now let's add it to Janus: 29 30 {% codetabs name="HTTPie", type="bash" -%} 31 http -v POST localhost:8081/apis "Authorization:Bearer yourToken" "Content-Type: application/json" < example.json 32 {%- language name="CURL", type="bash" -%} 33 curl -X "POST" localhost:8081/apis -H "Authorization:Bearer yourToken" -H "Content-Type: application/json" -d @example.json 34 {%- endcodetabs %} 35 36 This will create a proxy to `http://www.mocky.io/v2/595625d22900008702cd71e8` (which is a fake api) when you hit Janus on `GET /example`. 37 38 ## 2. Verify that your API has been added 39 40 41 You can use the REST API to query all available APIs and Auth Providers. Simply make a request 42 to `/apis`: 43 44 {% codetabs name="HTTPie", type="bash" -%} 45 http -v GET localhost:8081/apis "Authorization:Bearer yourToken" "Content-Type: application/json" 46 {%- language name="CURL", type="bash" -%} 47 curl -X "GET" localhost:8081/apis -H "Authorization:Bearer yourToken" -H "Content-Type: application/json" 48 {%- endcodetabs %} 49 50 ## 3. Forward your requests through Janus 51 52 Issue the following request to verify that Janus is properly forwarding 53 requests to your API. Note that by default Janus handles proxy 54 requests on port `:8080`: 55 56 {% codetabs name="HTTPie", type="bash" -%} 57 http -v GET http://localhost:8080/example 58 {%- language name="CURL", type="bash" -%} 59 curl -vX "GET" http://localhost:8080/example 60 {%- endcodetabs %} 61 62 A successful response means Janus is now forwarding requests made to `http://localhost:8080` to the elected upstream target (chosen by the load balancer) that we configured in step #1, and is forwarding the response back to us. 63 64 [Next](modify_endpoint.md) we'll learn how to modify existing endpoint.