If you call the remove.bg API you have to provide your API key for authentication. If you are worried about exposing this API key you can set up your own relay function on Microsoft Azure that injects the API key on the server and forwards all other parameters to the remove.bg API and then returns the result.
- It enhances the security of your front end
- Especially for mobile apps
- Use it as a boilerplate to do all kinds of things that our API can't do
Provider | URL | |
---|---|---|
Google Cloud Functions | https://github.com/remove-bg/remove-bg-serverless-gcf | |
Microsoft Azure Functions | https://github.com/remove-bg/remove-bg-serverless-azure |
For general reference check out the official docs: https://docs.microsoft.com/en-us/azure/developer/javascript/how-to/develop-serverless-apps
- Create a new function with Runtime stack
Node.js
, 14 LTS, choose your desired region - Click Deploy
- In your function Configuration open
Settings > Configuration
- Add a
Runtime environment variable
calledREMOVE_BG_API_KEY
and set it to your remove.bg API key
- Install the
Azure Functions
plugin and log in within Visual Studio Code (https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurefunctions) - Navigate to your functions in the Azure Tab in VSCode
- Open
Application Settings
and add a new Setting calledREMOVE_BG_API_KEY
using your remove.bg API key as value - Click on the
Deploy to Function App...
- Select your function in the popup
- Note the URL logged in the deploy output after
HTTP Trigger Urls:
- Replace remove.bg API endpoint with this URL
- Remove your API key from the header of your call
For general reference check out the official docs: https://docs.microsoft.com/en-us/azure/developer/javascript/tutorial/vscode-function-app-http-trigger/tutorial-vscode-serverless-node-test-local
- Your API key is configured in the
Application Settings
in theAzure Functions
- Launch locally with VSCode Launch config
Launch Azure Function locally