π·π½ββοΈ CRUD operations for Google Cloud Functions APIs for any generic Collection in Firestore.
- A Google Cloud Account.
- Billing Enabled.
- API and Firestore Access Enabled.
gcloud
CLI installed and in your$PATH
.- A preferred configuration created (
gcloud init
).
curl https://${DEFAULT_REGION}-${PROJECT}.cloudfunctions.net/api-firestore --data '{ "collection": "foo", "document": "foo-doc-1", "value": "{ "message": "hello from foo doc." }" }' -H "Content-Type: application/json"
The expected response:
{
"data": "OK"
}
Or in the case there is a failure:
{
"err":"Document, foo, already exists."
}
# Create a document
curl https://${DEFAULT_REGION}-${PROJECT}.cloudfunctions.net/api-firestore --data '{ "collection": "foo", "document": "foo-doc-1", "value": "{ "message": "hello from foo doc." }" }' -H "Content-Type: application/json"
# Get a document by its document name
curl https://${DEFAULT_REGION}-${PROJECT}.cloudfunctions.net/api-firestore?document=foo-doc-1
# Update a user by their username (id)
curl https://${DEFAULT_REGION}-${PROJECT}.cloudfunctions.net/api-firestore --data '{ "collection": "foo", "document": "foo-doc-1", "value": "{ "message": "hello from foo doc...again!" }" }' -H "Content-Type: application/json"
# Delete a user by their username
curl -X DELETE https://${DEFAULT_REGION}-${PROJECT}.cloudfunctions.net/api-firestore?document=foo-doc-1
First, fork or clone this repo, then:
npm i
You need to pass in your environment variables either in a .env.yaml
file or as command line arguements. Run the following command in the root of this repository, assuming a .env.yaml
file:
gcloud functions deploy api-firestore --runtime nodejs10 --trigger-http --memory 128MB --env-vars-file .env.yaml
You should receive a YAML like response in your terminal including the URL for the Cloud Function.
npm i -D
PROJECT={PROJECT} npm test
MIT