NTERAC

About

NTERAC is a minimal HTTP API server using Deno.

Usage

Quick start

Run the deno run --allow-all https://deno.land/x/nterac/scripts/clone-template.ts in the directory your app will be. This won't create any folders, so if it's ran in example folder, then it's example/main.ts for the files.
See the template for more here.

Start the server

This is the config:

{
  "tasks": {
    "start": "deno run --unstable --allow-all main.ts",
    "dev": "deno run --unstable --allow-all .nterac/dev.ts --devmode",
    "preview": "deno run --unstable --allow-all .nterac/preview.ts"
  },
  "imports": {
    "_/": "./",
    "nterac/": "https://deno.land/x/nterac/"
  }
}

As you can see, there are three tasks. From them, two will be useful to you: deno task dev and deno task preview.
These tasks are saved locally in the .nterac folder. You can add it to your .gitignore, if you want.

To start the server in local developement mode, run deno task dev. This runs with a file watcher, so the server doesn't need to be alwys restarted.

To prepare your server to a serverless environment, which doesn't support dynamic imports (like Deno Deploy), run deno task preview. This will create or update your exportmap.ts file. After that, it starts your server, but without any file watcher.
If you deploy your app, the entry point has to be the main.ts.

The api folder

The api folder should contain the routes. Routes are simple TypeScript files. An example would be the file api/hello.ts:

//write anything here to execute during preview generation
console.log('Hi Mom!');

export default function (_req: Request) {
  return new Response('Hello World!');
}

Root files are files in the root of a directory. These are named index.ts.

Hidden files are files hidden from the route detection. These start with a _. For example: _this_is_hidden.ts. Folders also work like this.

Keep in mind

There's a difference between /hello/ and /hello. See root files. If the file is named something like api/users.ts, then it is on the /users route, else if it is like api/human/index.ts then on the /human/ route.

This is a hobby project, but planned to maintain and update.

This project is in it's early stages, so it might be unstable, and things might change with later updates.

Directory-based routing

- projeckt-folder
  - api
    - endpoint1folder
      + endpoint11.ts
      + endpoint12.ts
    + endpoint2.ts
    + _hidden-endpoint.ts
  + exportmap.ts
  + main.ts

Logs

To log out more info, you can set the environment variable NTERAC_LOGS to true.

See more here.