Skip to content

itSubeDibesh/JAM

Repository files navigation

JAM (JavaScript API Maker) JavaScript MySQL Node.js Visual Studio Code

Table of Contents

  1. About JAM
    1. Todos
    2. Change Log
  2. Requirements
  3. Setup
  4. Creating API Endpoints
  5. Registering Route
  6. Importing Route File

About JAM

JAM(JavaScript API Maker) is a small API spitting framework build for rapid development. JAM is designed to simplify the API creation process.

Todos

Collaborators are heartily welcome and will be credited properly so if you are willing to be one, all the todos of JAM are listed on Todo File.

Change log

All the possible changes are logged on Changes file and don't hesitate to have a glance.


Requirements

As this project is built on JavaScript and Express all you need is Node JS and XAMPP or MySQL server.


Setup

Setting up JAM is pretty easy.

  1. Create a database on MySQL server
  2. Clone JAM fom github
  3. Rename .env.example file to .env
  4. Set Database Credentials in .env file as below
# ------------------------------
# Database Configuration
# ------------------------------
    DB_HOST = localhost
    DB_USER = root
    DB_Password = root
    DB_NAME = mydatabase
    DB_PORT = 3306
# ------------------------------

And finally open the terminal pointing to the cloned directory and run npm install after the installation completes you are ready to set some API endpoints.


Creating API Endpoints

Creating an API endpoint using the JAM framework is a piece of cake if you have your database created.

  1. Open endopints folder, copy and rename demo.js file to your table name in the database.
  2. Open the renamed file and rename demo from this line as your file name const _table = new table('demo');.
  3. Open route.conf.js
  4. Copy app.use('/demo', demo); and paste it inside constructor.
  5. Rename demo from app.use('/demo', demo); to your table name and also rename the import demo from "./endpoints/demo.js"; demo from import to your table name.
  6. Save all the changes and test your endpoint.

Your endpoint will look something like this http://localhost:8080/yourTableName. CRUD operations for the table have been assigned with the endpoint so you can use the following URLs to perform different actions as defined.

S.N Method Action URL Description
1. GET ALL /table Sends all the data
2. GET Paginate /table?count=10&page=4 Paginates data
3. GET Pick /table/{id} Picks Specific data
4. POST Insert /table Insert data according to payload
5. PUT Update /table/{id} Updates data according to payload
6. DELETE Delete /table/{id} Delets Specific data

NOTE: Here table means your table name and Insert and update payload is not defined on the above table. If you want to make other endpoints you know the drill. Just create a new file in the endpoints folder and register the route in route.conf.js like the first endpoint you created.


Registering Route

If you have successfully created your first endpoint then you might skip this section. If not then let me explain you in detail.

All the routes are registered on route.conf.js file which is located on root directory. Open the route.conf.js file and follow the steps.

  1. Import the route file you created. If you have not imported the route file and stuck on importing it then don't worry just click me.
  2. After you import the file you need to register the imported file to create an endpoint. To register endpoint create a new line under constructor.
  3. Copy and paste app.use('/demo', demo); on the new line and rename both demos with the imported filename.

That's it you have registered your route successfully.


Importing Route File

Importing a file is quite easy all you need to do is copy and paste import demo from "./endpoints/demo.js"; and replace both demos with your table name on route.conf.js file.

About

A simple JavaScript API maker using MySql and express server.

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published