NextJS GET request returns empty object
Answered
Bordin posted this in #help-forum
BordinOP
Hello, my api is returning an empty object even though there is results from the database
anyone knows that the issue is?
public async GetCategories(){
try{
let { data: Category, error } = await this.supabase
.from('Category')
.select('*')
if(error){
console.log(error);
}else{
console.log(Category)//results are available
return NextResponse.json(Category); //returned {} for some reasons
}
}catch(error){
console.log(error);
}
}anyone knows that the issue is?
Answered by American black bear
just return the object in getcategories instead of returning nextresponse.json
21 Replies
American black bear
ahh, is category an object?
it prolly is an array
BordinOP
yea
American black bear
try
NextResponse.json({categories: Category})American black bear
can you share your code, where you're using the function
cause nextresponse.json is supposed to be used for api routes 

this doesn't look like an api route
api route == route handlers FYI
BordinOP
export async function GET(){
const service = new CategoryReposiroty();
const result = service.GetCategories();
return NextResponse.json(result);
}uhm wait leme share the whole code
American black bear
just return the object in getcategories instead of returning nextresponse.json
Answer
American black bear
like a regular object
BordinOP
ey it worked
thannksyou
American black bear
np, if your problem is solved, consider marking the answer as solution
Original message was deleted
American black bear
^
@American black bear np, if your problem is solved, consider marking the answer as solution
BordinOP
i cant see the "app" thing
American black bear
it's already done, leave it. don't worry