Smallapi-js usage examples
Smallapi is a code plateform that helps developers craft, build and deploy APIs to the cloud in no time. Built on top of Javascript and MongoDB, Smallapi significantly reduces the amount of code you need to write and therefore increases code quality and time to market.
Try Smallapi for free. You can Get started here!
Smallapi-js is a small wrapper wrote in javascript that allows smallapi users to uses their APIs cloud functions from the client side.
- This project requires NodeJS (at least version 6) and NPM. Node and NPM are really easy to install. To make sure you have them available on your machine, try running the following command.
node --version
# v21.5.0
npm --version
# 10.2.4
-
This project is a demo project for the smallapi platform. It works by querying an api deployed from smallapi. Start by creating and deploying an api on smallpi by following the following tutorial.
-
Create a
.env
file at the root of the project with the keysAPI_URL
andAPI_KEY
like the following:
API_URL='my-api-url'
API_KEY='my-secret-key'
You can create the .env
file using the env.example
file as a template.
- Replace the values 'my-api-url' and 'my-secret-key' with the corresponding values from a space you have created on smallapi.
You can find the API_URL value in the
deployment
tab of your space: The API_URL value corresponds to the url generated in theDeploy link
section of your cloud space.
Regarding the API_KEY, you can find its value in the environment
tab of your space, in the section API Key Authorization
:
BEFORE YOU INSTALL: please read the prerequisites
Install the project packages using npm install
:
npm i
Run the project using npm start
:
# this will run the basic usecase by default
npm start
To run a specific usecase use npm run usecase
:
# run the basic usecase
npm run basic
- basic : Create a user then list all existing users in the users collection
- complex : Create some users random aged - grow them each stage while removing users over 99 years old until the collection reaches 7 users.
- create-random-users: Create random users - list and count all users in the colletion
- error-handling: Catch and handle an error raised when searching for a user that does not exist in the collection
- find-user-by-id: Find the first user created in the collection by their id
- find-users-by-query: Find all teen users (under 18 years old)
- remove-user-by-id: Remove the first user created in the collection by their id
- remove-users-by-query: Delete all users with the firstname "John"
- update-user-by-id: Update the age and email of the first user created in the collection by their id
- update-users-by-query: Update all users with the first name "John" with the first name "Joan"
Learn more about the generated API here.
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Add your changes:
git add .
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request 😎
MIT License © Anagbla Joan (tutanck)
Thanks goes to these wonderful people for their contribution:
Anagbla Joan |
This project follows the all-contributors specification. Contributions of any kind welcome!