Fast, unopinionated, minimalist API framework written in jQuery.
jQuery together with JSDom powers the database and routing system, which are html files respectively. The web side is handled by fastcgi and nginx.
Features
- Efficient routing (jQuery)
- Out of the box database support (jQuery)
- Easily built controllers and models
- Very (very) unopinionated
- Only two dependencies; jQuery and JSDom
Quick Start
All you need is Nodejs and running npm install
. The routing and the database are both powered by jQuery, so there are no other dependencies. You can also run it via Docker (as explained below).
Routing
The routing file looks like this:
<html>
<head></head>
<body>
<a href="/books" method="GET">get_books</a>
<a href="/users" method="GET">get_users</a>
<a href="/" method="GET">home</a>
</body>
</html>
The correct route is selected like this:
$("a").each(function(value, test) {
if ( $(this).attr("method") == request_method && $(this).attr("href") == request_endpoint ) {
route = $(this).text();
}
});
Very effective. Very efficient. Very jQuery.
Database
Out-of-the-box database support through jQuery. A database file looks like this:
<html>
<head></head>
<body>
<ul>
<li author="Terry Pratchett" number_of_pages=394>Going Postal</li>
<li author="Neil Gaiman" number_of_pages=465>American Gods</li>
</ul>
</body>
</html>
You can query like this:
$( 'ul li' ).each(function(value, test) {
if (!search || $(this).text().toLowerCase().includes(search.toLowerCase())) {
let book = {
"name": $(this).text(),
"number_of_pages": $(this).attr("number_of_pages")
}
books.push(book);
}
});
You can add records:
$('<li/>', {
"text": book.name,
"author": book.author,
"number_of_pages": book.number_of_pages
}).appendTo('ul');
fs.writeFileSync(db_file, window.document.documentElement.outerHTML, { mode: 0o755 });
Deletions are super easy too:
let removed = $(`ul li[id=${id}]`).remove();
fs.writeFileSync(db_file, window.document.documentElement.outerHTML, { mode: 0o755 });
Docker
You can easily run it with Docker:
$ git clone https://github.com/koffiebaard/jquery-back-end/
$ docker build -t jquery-back-end .
$ docker run --name=jquery-back-end-container -d -p 6969:6969 jquery-back-end
You can now view the API at: http://localhost:6969.
Contributing
Feel free to contribute! Ping me or send a pull request and let's go.
License
jQuery back-end is under the MIT license, but without me shipping the copyright text with the project. That's too much effort.