URL Shortener Plugin For OpenAgents
This plugin is designed to shorten long URLs using the CleanURI API. It takes a long URL as input and returns a shortened version of the URL as output.
GitHub : https://github.com/nafwan/URL-Shortener-for-OpenAgents
Usage
- Install the Extism CLI and the URL Shortener Plugin.
- Run the plugin with the long URL as input:
$ extism call plugin.wasm run --input 'https://openagents.com/' --wasi --allow-host='cleanuri.com' https://cleanuri.com/kd9P71
How it Works
- The plugin reads the input URL and validates it to ensure it doesn't contain any spaces, tabs, or newlines.
- The long URL is encoded into a JSON payload.
- An HTTP POST request is sent to the CleanURI API endpoint with the JSON payload as the request body.
- The API response is parsed, and any errors are handled appropriately.
- If the API response is successful, the shortened URL is set as the plugin output.
Error Handling
The plugin handles the following types of errors:
- Invalid input URL (contains spaces, tabs, or newlines)
- Failure to create the request payload
- API request failure (non-200 status code)
- Failure to parse the API response
- Errors returned by the CleanURI API
If any of these errors occur, the plugin will print an error message and exit with a non-zero status code.