NTERAC
About
Nterac is a minimal HTTP API server using Deno.
Usage
Quick start
Create a file named exportmap.ts
into the same directory as your main.ts
.
Paste the following code inside:
export const manifest: Record<string, any> = {}
This will ensure, that the server starts without errors as the code can access the manifest and therefore won't be an error of module not found
.
After that, you can start the server.
Start the server
Init a server in the main.ts
(this code can also be copypasted):
import { Server } from "https://deno.land/x/nterac/mod.ts";
// use it only in developement to generate the exportmap.ts file
Deno.env.set('NTERAC_DEVMODE', 'on');
const server = await new Server().init({
manifest: manifest
});
server.serve();
After that the serve function will use the files in the api
folder.
Run deno run --allow-all main.ts
.
To activate dev mode, which will generate the exportmap.ts file, set an environment variable NTERAC_DEVMODE
to on
;
The api folder
The api
folder should contain the routes. Routes are simple TypeScript files. An example would be the file api/hello.ts
:
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.
You don't need to use the same names as we used (like main.ts
).
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.
To try it out, clone the repo, start the main.ts
file using deno run --allow-all main.ts
.
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 on
.