Menu

Check the link before you spend the API call: validating pasted URLs on a video downloader
📰

Check the link before you spend the API call: validating pasted URLs on a video downloader

DEV Community: php·Mobeen Ahmed·4 days ago
#BWjmb3tZ
#devto#dev#tiktok#visitor#host
Reading 0:00
15s threshold

Every API call on my downloader costs me something. I am on the free tier of a few RapidAPI services, and each of those services gives me a fixed number of calls a month. The visitor does not see any of that. They paste a link, tap Download, and expect a video. So one of the first things I learned building ramrom.io was this: never spend an API call on a link you already know is useless.

The fix is boring, and that is the point. Before anything touches the network, the pasted link gets validated in the browser. The first check is the shape of it. A valid URL has to parse, it has to use http or https, and it has to actually have a host. That alone catches the typos, the half-pasted links, and the text that is not a link at all. A visitor who pastes "watch this one" by accident gets a plain message straight away instead of a spinner that ends in a confusing error.

The second check is the one that saves the quota.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.