WaspW
Waspβ€’2y ago
Ghar

First time wasp user, Unable to add super simple custom API

First time using wasp :) so it is probably user error.

I am trying to add a basic API endpoint as follows.

In app/main.wasp I have
api helloWorld {
  fn: import { helloWorld } from "@src/server/apis.ts",
  httpRoute: (GET, "/hello-world")
}


in app/src/server/apis.ts I have
import { Request, Response } from 'express';

export const helloWorld = async (_req: Request, res: Response) => {
  res.setHeader('Content-Type', 'application/json');
  res.status(200).json({ message: "Hello World!" });
};

I am expecting a JSON response but instead get HTML

curl http://localhost:3000/hello-world
returns html not the expected json

browsing http://localhost:3000/hello-world
returns an html page with layout.

Additonal info:
Request URL:
http://localhost:3000/hello-world
Request Method: GET
Status Code: 304 Not Modified
Remote Address: 127.0.0.1:3000
Referrer Policy: strict-origin-when-cross-origin
Was this page helpful?