# jetql

> 🚀 JetQL JetQL is a query language for the implementation of Rest APIs on both the server and the client. JetQL also comes with a fro

Latest version **1.0.0** (published 2020-09-04) · ISC license · 0 weekly downloads

## Install

```sh
npm install jetql
pnpm add jetql
yarn add jetql
bun add jetql
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2020-09-04 |
| First published | 2020-09-04 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 18.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Sammwy |
| Maintainers | sammwy |

## Links

- npm: https://www.npmjs.com/package/jetql
- Repository: https://github.com/sammwyy/jetql
- Homepage: https://github.com/sammwyy/jetql#readme
- Issues: https://github.com/sammwyy/jetql/issues
- npm.io page: https://npm.io/package/jetql

## Recent versions

- 1.0.0 (latest) — 2020-09-04

## README

<img src="https://raw.githubusercontent.com/sammwyy/jetql/master/demo/icon.png" align="right" height="150px">
<h1>🚀 JetQL</h1>
<p>JetQL is a query language for the implementation of Rest APIs on both the server and the client. JetQL also comes with a frontend script that easily connects it to the backend.</p>

<p>JetQL is inspired by <a href="https://github.com/graphql"> GraphQL </a> but extremely simplified.</p>
<p>You can donate to the project in <a href="https://paypal.me/sammwy">Paypal</a>, in <a href="https://ko-fi.com/sammwy">Ko-fi</a> or in <a href="https://patreon.com/sammwy">Patreon</a></p>

### JetQL Features:
- 🧹 Clean Sintaxis.  
- 🔗 Compatble with POST, PUT, DELETE and GET Requests.  
- 🚀 Fast and Lightweight.  
- 🙏 Express.js compatible.  

### How does this work?
<p>JetQL registers all routes that start with /api, thus intercepting the request. Following this, it analyzes the body of the request (In case of being POST) or analyzes the url used (In case of being GET) to obtain a query command and execute it internally.</p>

The body has this format:
```json
{
  "action": "get/delete/add/update/edit/list",
  "route": "...",
  "props": {},
  "args": {}
}
```

And the url (in case of being GET) has this format:  
`http://example.com/api/<route>/<action>/<props>/<args>`

### Get started with JetQL
**Implementation with express:**  
```javascript
const express = require("express");
const JetQL = require("jetql");

const app = express();
const jetql = JetQL.Server();

app.use(express.json());
app.use(jetql.express());

app.listen(3000);
```

**Implementation in the frontend:**  
(Import the [script file](https://github.com/sammwyy/jetql/blob/master/dist/%40jetql.js))
```html
<script src="@jetql.js">
```

(Send a request)
```html
<button onclick="sendRequest()">Send request</button>
<script>
  async function sendRequest () {
    let data = await jetql("user").get({
        username: "sammwy"
    });

    if (data.success) {
      alert("Username exists! and her value is " + data.result);
    } else {
      alert(data.error);
    }
  }
</script>
```

**Test route in backend:**
```javascript
  jetql.addRoute({
    action: "get",
    route: "user",
    callback: function (query) {
      if (query.props.username == "sammwy")
        query.finish(18);
      else
        query.drop("User isn't exists");
    }
  });
```

### Examples
**Add a route (Method #1):**  
```javascript
jetql.addRoute({
  action: "get",
  route: "user",
  callback: (query) => {
    console.log(query);
  }
});
```

**Add a route (Method #2):**  
```javascript
jetql.addRoute("add", "user", (query) => {
  console.log(query);
});
```

**Add external route:**   
```javascript
// index.js
jetql.use(require("./external.js"));

// external.js
const JetQL = require('jetql');
const router = JetQL.Router();

router.addRoute({ ... });
router.addRoute({ ... });
router.addRoute({ ... });

module.exports = router;
```

### Demo
Try jetql with the demo project.  

1. Clone the repository  
2. Use node ./jetql.test.js in the folder.  
3. Open https://127.0.0.1:4000/  

### Methods
**End the request with a successful result:**  
```javascript
query.finish(result);
```

<hr>

**End the request with a 404 error and a message:**  
```javascript
query.drop(message);
```

<hr>

**The request ends with a 500 error and a message:**  
```javascript
query.error(message);
```

<hr>

**Get the client's request:**  
```javascript
query.request;
```

<hr>

**Get the response to the client:**  
```javascript
query.response;
```

<hr>

**Add a router object and all its routes to the JetQL instance:**  
```javascript
jetql.use(router);
```

<hr>

**Add a route to the jetql instance:**  
```javascript
jetql.addRoute({action: ..., route: ..., callback: () => { ... } });
```

<hr>

**Add a route to the jetql instance:**  
```javascript
jetql.addRoute(action, routeName, callback);
```

<hr>

**Gets the express middleware:**  
```javascript
jetql.express();
```

<hr>

**Gets the http middleware:**  
```javascript
jetql.http();
```

<hr>

**Instantiate jetql:**  
```javascript
jetql.Server();
```

---
_Source: https://npm.io/package/jetql · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
