𝐗-𝐥𝐞𝐦
𝐗-𝐥𝐞𝐦
SSolidJS
Created by 𝐗-𝐥𝐞𝐦 on 4/10/2025 in #support
Solid start call
Just getting into solid start. Going through this documentation to try and get api routes set up so I can fetch data: https://docs.solidjs.com/solid-start/building-your-application/api-routes I have two files that look like this
// src/routes/index.tsx
import { createAsync, query } from "@solidjs/router";
import { For } from "solid-js";

const getPosts = query(async () => {
const posts = await fetch("http://localhost:3001/api/hello");
return await posts.json();
}, "posts");

export default function Home() {
const posts = createAsync(() => getPosts());

return (
<section>
<ul>
<For each={posts()}>{(post) => <li>{post.title}</li>}</For>
</ul>
</section>
);
}
// src/routes/index.tsx
import { createAsync, query } from "@solidjs/router";
import { For } from "solid-js";

const getPosts = query(async () => {
const posts = await fetch("http://localhost:3001/api/hello");
return await posts.json();
}, "posts");

export default function Home() {
const posts = createAsync(() => getPosts());

return (
<section>
<ul>
<For each={posts()}>{(post) => <li>{post.title}</li>}</For>
</ul>
</section>
);
}
// src/routes/api/hello.ts
import { APIEvent, json } from "solid-start";

export async function GET() {
console.log("testing")
return json({ message: "Hello from the backend!" });
}

export async function POST({ request }: APIEvent) {
const body = await request.json();
return new Response(JSON.stringify({ echo: body }), {
headers: { "Content-Type": "application/json" }
});
}
// src/routes/api/hello.ts
import { APIEvent, json } from "solid-start";

export async function GET() {
console.log("testing")
return json({ message: "Hello from the backend!" });
}

export async function POST({ request }: APIEvent) {
const body = await request.json();
return new Response(JSON.stringify({ echo: body }), {
headers: { "Content-Type": "application/json" }
});
}
I can't seem to get it to call the GET (or POST) route. Not sure where I'm going wrong. Thanks for any help!
14 replies
SSolidJS
Created by 𝐗-𝐥𝐞𝐦 on 1/22/2024 in #support
Getting import errors
No description
8 replies