Skip to content

dipan29/Qwikstore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📙 QwikStore 📙

A Simple and Quick Datastore API

Introduction

This is a simple API that allows you to create certain properties (in form of API Keys) under which you can create unlimited variables (aka entities) that can be fetched or updated via GET, PUT, POST methods from anywhere. The api is currently hosted at Heroku that can be used as your public endpoint if you don't want to deploy your own instance. The followin section shows the available endpoints and the respective requests and responses. You can find below how to deploy your own instance if you wish to make one.


Creating your Own Instance of QwikStore

Clone this repository to your local system to make the necessary changes and deploy it to your own instance.

1. Create an MongoDB Atlas account.

Create and account at MongoDB and sign in to that account.
Once you are signed in, make a cluster as per your requirement (free tier will surely suffice for basic development or testing) and generate its connection uri.
Allowlist 0.0.0.0/0 in the Network section so that your application can connect to the mongo instance.

2. Create an Environment File

In the root of the project, create a new file named .env with your preferred text editor.
Add the following to the file.

connection_uri = "mongodb+srv://username:[email protected]/database?retryWrites=true&w=majority"
PORT = 5000
access_key = "a-random-access-key"


Change the connection_uri to the provided connection uri and give a strong password as your access key. This access_key will allow you to list all the created entities.

3. Run your Local Deployment Server

Run the following commands inside the root folder of the project.
npm i, and wait till the packages and dependencies are installed.
To test the API enter npm run dev to start the local endpoint at http://localhost:5000/.
If you make any changes nodemon will notice as required and restart your application.

4. Deploy to Heroku and create your own Public Endpoint

Create and account at Heroku and after verification head on to Create Deployment. Give a unique name and choose a region. Any region will work, but you may choose the region close to your location.
Open Teriminal and enter the following -

  1.  heroku git:remote -a your-app-name
  2.  git add --all && git commit -m "Deployment"
  3.  heroku config:set connection_uri=mongodb-connection-uri access_key=your-access-key
  4.  git push heroku main

Make sure to change your application name, mongodb connection uri and your access key.
Wait till the deployment is over and you will be ready to use it using the endpointhttps://your-app-name.hrokuapp.com.

You deployment is ready. Every time you commit a change, run command 4 to update your public endpoint.


API Documentation - Public API Endpoint

These are the available endpoints that are availabe in this application at the moment. Before getting started with the applicaition, you need to create an API Key to allow the API interactions. All the content-types are 'application/json'.

1. Creating an API Key [Important]

POST https://qwikstore.herokuapp.com/api/create/
This creates and API KEY based on the email address provided that is later used to identify the details.
Parameters -
{
 "owner": "[email protected]"
}

Response [200 OK] -
{
 "message": "Success",
 "api_key": "YOUR-APIKEY-1010",
 "additional_text": "New API Key was created successfully. Do not lose this key. Store it in a safe place."
}

2. Delete Created API Key

POST https://qwikstore.herokuapp.com/api/delete/
If you wish to delete your api key, this will also remove all the entities created under it, you can delete your key as follows.
Parameters -
{
 "owner": "[email protected]",
 "api_key": "YOUR-APIKEY-1010"
}


3. Create a New Entity or Update the Entity Type

POST https://qwikstore.herokuapp.com/create/
An entity is a variable storage or data-store that can store any type of data as specified during the time of its creation. This same route can be reused by passing the type to update the variable type.
Entity Names should not contain any white spaces or special characters.
Parameters -
{
 "api_key": "YOUR-APIKEY-1010",
 "entity": "your-entity-name",
 "content": "initial-value",
 "type": "[Optional Parameter], Accepted Values - number, string, boolean"
}

Response - [200 OK]
{
 "message": "Accepted",
 "additional_text": "New Entity has been successfully created.",
 "entity": "your-entity-name"
}

4. Retrive Value of an Entity

GET https://qwikstore.herokuapp.com/api-key/entity-name/
This GET Method returns the current state or contents of the entity in the response.body [200 OK].

POST https://qwikstore.herokuapp.com/content/
You can also get the value via a POST Method as defined below.
Parameters -
{
 "api_key": "YOUR-APIKEY-1010",
 "entity": "your-entity-name"
}

The request returns the current state or contents of the entity in the response.body [200 OK].

5. Setting the Content of an Entity

POST https://qwikstore.herokuapp.com/set/
This method permits the update of the entity provided that the type remains the same. To check the type you can use the option parameter in the /create (Endpoint No. 3) route.
Parameters -
{
 "api_key": "YOUR-APIKEY-1010",
 "entity": "your-entity-name",
 "content": "Content - number, string or boolean"
}

Make sure you don't use quotes for sending number or boolean values, else this will cause and error to fire up.

GET https://qwikstore.herokuapp.com/set/api-key/entity-name/content/
This will do the same as above and allows you to set the value of the existing entity under your API Key.


Rest API Documentation will be added soon.


Contributions

Feel free to make your changes, bug-fixes or feature additions and make pull request to this repository. This project is completely open-source and you are free to modify, use or distribute it as-it-is or as required.

Creator Contact - Dipan Roy