DEV Community

Cover image for API using Deno and ElyasiaJS
Santosh Anand
Santosh Anand

Posted on

2

API using Deno and ElyasiaJS

Elysia JS: TypeScript with End-to-End Type Safety, unified type system and outstanding developer experience. Supercharged by Bun.

Elasia is faster than Node, PHP and Gin as well

Image description

Here is simple code to create API

1. Install Deno: You can install Deno by following the instructions on its official website: https://deno.land/
2. Initialize a new Deno project:



mkdir my-api
cd my-api
touch server.ts


Enter fullscreen mode Exit fullscreen mode


deno install --allow-read --allow-write --allow-net --unstable -n elyasia https://deno.land/x/elyasia/cli.ts


Enter fullscreen mode Exit fullscreen mode

4. Create your API endpoint in server.ts:



import { App, Router } from "https://deno.land/x/elyasia@v0.8.0/mod.ts";

const app = new App();
const router = new Router();

// Define your API routes
router.get("/hello", (ctx) => {
  ctx.response.body = "Hello, World!";
});

app.use(router.routes());
app.use(router.allowedMethods());

// Start the server
app.listen({ port: 8000 });
console.log("Server is running on http://localhost:8000");



Enter fullscreen mode Exit fullscreen mode

5. Run your server:



deno run --allow-net --allow-read server.ts



Enter fullscreen mode Exit fullscreen mode

Now your API should be running on http://localhost:8000. You can test it by accessing http://localhost:8000/hello in your browser or using tools like curl or Postman.

This is a basic example to get you started. You can expand it by adding more routes, middleware, error handling, etc., based on your requirements.

for more information checkout https://elysiajs.com/

Image of Datadog

Master Mobile Monitoring for iOS Apps

Monitor your app’s health with real-time insights into crash-free rates, start times, and more. Optimize performance and prevent user churn by addressing critical issues like app hangs, and ANRs. Learn how to keep your iOS app running smoothly across all devices by downloading this eBook.

Get The eBook

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more