Skip to content

tutanck/small-demo

Repository files navigation

Smallapi-js demo

Smallapi-js usage examples

What is Smallapi?

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!

What is Smallapi-js?

Smallapi-js is a small wrapper wrote in javascript that allows smallapi users to uses their APIs cloud functions from the client side.

Table of contents

Prerequisites

  1. 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
  1. 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.

  2. Create a .env file at the root of the project with the keys API_URL and API_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.

  1. 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: image The API_URL value corresponds to the url generated in the Deploy 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: image

Installation

BEFORE YOU INSTALL: please read the prerequisites

Install the project packages using npm install:

npm i

Usage

Run the project using npm start:

# this will run the basic usecase by default
npm start

Usecases

To run a specific usecase use npm run usecase:

# run the basic usecase
npm run basic

List of use cases

  1. basic : Create a user then list all existing users in the users collection
  2. complex : Create some users random aged - grow them each stage while removing users over 99 years old until the collection reaches 7 users.
  3. create-random-users: Create random users - list and count all users in the colletion
  4. error-handling: Catch and handle an error raised when searching for a user that does not exist in the collection
  5. find-user-by-id: Find the first user created in the collection by their id
  6. find-users-by-query: Find all teen users (under 18 years old)
  7. remove-user-by-id: Remove the first user created in the collection by their id
  8. remove-users-by-query: Delete all users with the firstname "John"
  9. update-user-by-id: Update the age and email of the first user created in the collection by their id
  10. update-users-by-query: Update all users with the first name "John" with the first name "Joan"

Learn more

Learn more about the generated API here.

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Add your changes: git add .
  4. Commit your changes: git commit -am 'Add some feature'
  5. Push to the branch: git push origin my-new-feature
  6. Submit a pull request 😎

License

MIT License © Anagbla Joan (tutanck)

Contributors ✨

Thanks goes to these wonderful people for their contribution:


Anagbla Joan

This project follows the all-contributors specification. Contributions of any kind welcome!

Releases

No releases published

Packages

No packages published