A Java Cloud Function for generating a Short URL using tinyurl and bitly
Supported providers: tinyurl, bitly
Bitly Example input:
{
"provider": "bitly",
"url": "https://google.com"
}
Bitly Example output:
{
"success": true,
"url": "https://bit.ly/3CywbjA"
}
Tinyurl Example input:
{
"provider": "tinyurl",
"url": "https://google.com"
}
Tinyurl Example output:
{
"success": true,
"url": "https://tinyurl.com/dck67zxk"
}
Error Example output:
{
"success": false,
"message":"Provided URL: https://xyz is not valid, please provide a valid, correctly formed URL"
}
List of environment variables used by this cloud function. These must be passed within 'variables' section of the request:
BITLY_API_KEY - Pass this API key if the requested provider is bitly. This API key would be the access token used by bitly for generating a short URL.
TINYURL_API_KEY - Pass this API key if the requested provider is tinyurl. This API key would be the access token used by tinyurl for generating a short URL.
- Clone this repository, and enter this function folder:
$ git clone https://github.com/open-runtimes/examples.git && cd examples
$ cd java/short_url_generator
- Enter this function folder and build the code:
docker run -e INTERNAL_RUNTIME_ENTRYPOINT=Index.java --rm --interactive --tty --volume $PWD:/usr/code openruntimes/java:v2-11.0 sh /usr/local/src/build.sh
As a result, a code.tar.gz
file will be generated.
- Start the Open Runtime:
docker run -p 3000:3000 -e INTERNAL_RUNTIME_KEY=secret-key --rm --interactive --tty --volume $PWD/code.tar.gz:/tmp/code.tar.gz:ro openruntimes/java:v2-11.0 sh /usr/local/src/start.sh
Your function is now listening on port 3000
, and you can execute it by sending POST
request with appropriate authorization headers. To learn more about runtime, you can visit Java runtime README.
- This function is designed for use with Appwrite Cloud Functions. You can learn more about it in Appwrite docs.
- This example is compatible with Java 11.0. Other versions may work but are not guarenteed to work as they haven't been tested.