Hi,
I am wanting to implement a simple URL shortening service using Edge. I just need to read the context path in the URI and based on its value return a 301 HTTP response with new location.
Ideally I would like to maintain the context path to new URL as a key/value store.
Any ideas?
Regards,
David
Solved! Go to Solution.
@David Turner Thats exactly the scenario that is covered in our docs for the key value map policy. Please follow the example listed there: http://apigee.com/docs/api-services/reference/key-value-map-operations-policy
As you know most of the URI constructs are made available within the API proxy as a variable. Depending on what you need to extract you can use the {proxy.pathsuffix} or other variables. So essentially create a KVM using APIs. You can use your "path" as your key & the value will be the new location URL.
Once you do that in your API Proxy lookup the KVM & return the response with the new URL.
------------------------
I am including instructions & a sample proxy below
1) Create a Environment Level Key Value Map. Here is how your URLMap (Create using APIs) needs to look like. The "name" is your "path" & they "value" is your "new location URL":
{ "name" : "URLMap", "entry" : [ { "name" : "cnn", "value" : "www.cnn.com" }, { "name" : "yahoo", "value" : "www.yahoo.com" } , { "name" : "msnbc", "value" : "www.msnbc.com" } ] }
2) Import this proxy as an API Bundle.
3) Run the curl command (or use any other REST Client)
curl -i http://{your-org}-{your-env}.apigee.net/urlshorte...
Once you run the curl command & assuming you have populated the key value map correctly, you should see the response like this:
HTTP/1.1 302 www.cnn.com Date: Wed, 23 Sep 2015 18:13:23 GMT Content-Type: text/plain Content-Length: 11 Connection: keep-alive Server: Apigee Router
Hope this helps.