github.com/hellofresh/janus@v0.0.0-20230925145208-ce8de8183c67/docs/quick_start/modify_endpoint.md (about) 1 # Modify (Update/Delete) an endpoint 2 3 As your infrastructure grows and changes you need to modify existing endpoints configurations and delete unused one. In this section we'll add one more endpoint, like we did in the last section, will make some changes to it and then remove it. 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-modify.json` file containing your endpoint configuration: 10 11 ```json 12 { 13 "name" : "my-endpoint-to-modify", 14 "active" : true, 15 "proxy" : { 16 "listen_path" : "/temporary/*", 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-modify.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-modify.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 /temporary`. 37 38 By this point this is exactly what we did in the previous section, when we added first endpoint. 39 40 You can make sure that the configuration is created using an API, same as we did before 41 42 {% codetabs name="HTTPie", type="bash" -%} 43 http -v GET localhost:8081/apis "Authorization:Bearer yourToken" "Content-Type: application/json" 44 {%- language name="CURL", type="bash" -%} 45 curl -X "GET" localhost:8081/apis -H "Authorization:Bearer yourToken" -H "Content-Type: application/json" 46 {%- endcodetabs %} 47 48 And that it proxies requests to a desired destination, again, same as we did previously 49 50 {% codetabs name="HTTPie", type="bash" -%} 51 http -v GET http://localhost:8080/temporary 52 {%- language name="CURL", type="bash" -%} 53 curl -vX "GET" http://localhost:8080/temporary 54 {%- endcodetabs %} 55 56 ## 2. Update existing endpoint 57 58 Updating existing endpoint is almost the same as creating new one except for the method and api endpoint used. 59 60 First, let's modify a file containing endpoint configuration and change `active` to `false` to deactivate existing endpoint, so the resulting file will look like this: 61 62 ```json 63 { 64 "name" : "my-endpoint-to-modify", 65 "active" : false, 66 "proxy" : { 67 "listen_path" : "/temporary/*", 68 "upstreams" : { 69 "balancing": "roundrobin", 70 "targets": [ 71 {"target": "http://www.mocky.io/v2/595625d22900008702cd71e8"} 72 ] 73 }, 74 "methods" : ["GET"] 75 } 76 } 77 ``` 78 79 To modify an endpoint we'll use the same `/apis` REST API endpoint, but with the `PUT` method and endpoint name, that is set in the `name` field, as resource: 80 81 {% codetabs name="HTTPie", type="bash" -%} 82 http -v PUT localhost:8081/apis/my-endpoint-to-modify "Authorization:Bearer yourToken" "Content-Type: application/json" < example-modify.json 83 {%- language name="CURL", type="bash" -%} 84 curl -X "PUT" localhost:8081/apis/my-endpoint-to-modify -H "Authorization:Bearer yourToken" -H "Content-Type: application/json" -d @example-modify.json 85 {%- endcodetabs %} 86 87 Make sure that the configuration is modified 88 89 {% codetabs name="HTTPie", type="bash" -%} 90 http -v GET localhost:8081/apis "Authorization:Bearer yourToken" "Content-Type: application/json" 91 {%- language name="CURL", type="bash" -%} 92 curl -X "GET" localhost:8081/apis -H "Authorization:Bearer yourToken" -H "Content-Type: application/json" 93 {%- endcodetabs %} 94 95 And that it is not proxying requests anymore 96 97 {% codetabs name="HTTPie", type="bash" -%} 98 http -v GET http://localhost:8080/temporary 99 {%- language name="CURL", type="bash" -%} 100 curl -vX "GET" http://localhost:8080/temporary 101 {%- endcodetabs %} 102 103 ## 3. Delete existing endpoint 104 105 Some endpoints become outdated and it does not make sense to store all of them in non-active state, so we can simply remove them. 106 107 To modify an endpoint we'll use the same `/apis` REST API endpoint, but with the `DELETE` method and endpoint name, that is set in the `name` field, as resource: 108 109 {% codetabs name="HTTPie", type="bash" -%} 110 http -v DELETE localhost:8081/apis/my-endpoint-to-modify "Authorization:Bearer yourToken" 111 {%- language name="CURL", type="bash" -%} 112 curl -X "DELETE" localhost:8081/apis/my-endpoint-to-modify -H "Authorization:Bearer yourToken" 113 {%- endcodetabs %} 114 115 Make sure that the configuration is removed 116 117 {% codetabs name="HTTPie", type="bash" -%} 118 http -v GET localhost:8081/apis "Authorization:Bearer yourToken" "Content-Type: application/json" 119 {%- language name="CURL", type="bash" -%} 120 curl -X "GET" localhost:8081/apis -H "Authorization:Bearer yourToken" -H "Content-Type: application/json" 121 {%- endcodetabs %} 122 123 [Next](add_plugins.md) we'll learn how to add plugins to our endpoint.