0

I working with next for creating a basic API tha read a local file json.

I would like to make a dynamic api base on what call recive

My api folder is

api
--book
---[id].js
----content
-----[id].js

So I could make a get request to https.../book/1 and also to https.../book/1/content/4

I'am right? Is possible do it?

I've try but with no good result

Thanks

2
  • if your logic is right, it would be -book; --[id]; ---content; ----[id] without the .js Commented Sep 22, 2022 at 0:06
  • No, because [id].js is where there is the handler Commented Sep 22, 2022 at 8:25

1 Answer 1

1

Yes I think you could do it like this:

api
  book // folder
    [bookId] // folder
      index.js // /api/book/1 endpoint
      content // folder
        [contentId].js // /api/book/1/content/4 endpoint

Edit: add image of folder structure

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

No, this is not right
I must have misunderstood your question. Are you trying to have /api/book/[someBookId] and /api/book/[someBookId]/content/[someContentId] as two valid endpoints? If so the above achieves this.
I have added an image of the folder structure i used and have tested both endpoints successfully.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.