Serverless service that makes Realtor API requests on behalf of the user in order to keep the API key secret.
NOTICE: This service can be customised according to your needs and the API used.
-
Install serverless framework (run command as
sudo
if you're using Linux)$ npm i -g serverless
-
Create an AWS IAM user or use credentials of an existing one
-
Set credentials so that Serverless knows what account to connect to when you run any terminal command
$ serverless config credentials \
--provider aws \
--key YOUR_ACCESS_KEY_ID \
--secret YOUR_SECRET_ACCESS_KEY
-
Create a service
$ serverless create --template aws-nodejs --path /path/to/your/api-requests-dispatcher
-
Clone this repository to your local machine and replace the files
$ git clone https://github.com/petruborta/api-requests-dispatcher.git
-
In
serverless.yml
, replace the value ofregion
(line 11) with your own region -
Create
secrets.json
and replace for"YOUR_REALTOR_API_KEY"
with your Realtor API keyYou can change
NODE_ENV
's value to production andDOMAIN
's value to your actual domain, once it's ready for production
{
"NODE_ENV": "dev",
"REALTOR_API_KEY": "YOUR_REALTOR_API_KEY",
"DOMAIN": "*"
}
-
Deploy the API to AWS Lambda
$ serverless deploy
The endpoint will be logged to the console once it's deployed
-
Test the API
$ curl --header "Content-Type: application/json" \
--request GET \
--data '{"realtorEndpoint":"city-and-state-code,"location":"Chicago"}' \
https://{id}.execute-api.{region}.amazonaws.com/{stage}/send
Project is: functionally finished, but the code can be refactored in a more elegant manner
Followed this tutorial to implement a serverless contact form and refactored the code to make API requests instead and send the responses back to user, without leaking the API key
Created by @petruborta - feel free to contact me!