JAM(JavaScript API Maker) is a small API spitting framework build for rapid development. JAM is designed to simplify the API creation process.
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.
All the possible changes are logged on Changes file and don't hesitate to have a glance.
As this project is built on JavaScript and Express all you need is Node JS and XAMPP or MySQL server.
Setting up JAM is pretty easy.
- Create a database on MySQL server
- Clone JAM fom github
- Rename
.env.example
file to.env
- 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 an API endpoint using the JAM framework is a piece of cake if you have your database created.
- Open endopints folder, copy and rename
demo.js
file to your table name in the database. - Open the renamed file and rename demo from this line as your file name
const _table = new table('demo');
. - Open
route.conf.js
- Copy
app.use('/demo', demo);
and paste it inside constructor. - Rename demo from
app.use('/demo', demo);
to your table name and also rename theimport demo from "./endpoints/demo.js";
demo from import to your table name. - 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.
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.
- 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.
- 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.
- 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 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.