#✅ - Can't add additional route

24 messages · Page 1 of 1 (latest)

craggy nest
#

Hello. Could you help me please with adding additional route?
First, I'm created the route /posts/:id and successful deployed it
Next, I try to create /posts route with the posts list, but get an error
I tried to remove all changes and create new one, but this action wasn't help me..

craggy nest
#

Additional information, how to reproduce (without changing the codebase):

  1. amplify api add
    /posts
    /posts/{postId}
  • different Lambda functions
  1. amplify push
  2. got error
    It's a strange for me and couldn't find the solution..
    Please help me with the advice.
    Thanks before!
tiny ingot
#

This is what i've understood from your request for help. You created a REST api with a path: /posts. With this api you have a handler function.

#

You get an issue when you try to create an additional path: /posts/{postId}. With this api you are unable to create the handler function.

#

If my understanding is correct... i would suggest you the handle the /posts/:postId route in your first postshandler function.

craggy nest
#

@tiny ingot Thanks, I have tried this option before, but it's not help me...
For now, I'm tried yet one and have an error..

#

Steps:

? Select from one of the below mentioned services: REST
√ Select the REST API you want to update: · PostApi
√ What would you like to do? · Remove path
? Select the path to remove /posts/{postId}
✅ Successfully updated resource```

```amplify function remove PostHandle

? Are you sure you want to delete the resource? This action deletes all files related to this resource from the backend
directory. Yes
✅ Successfully removed resource```

```amplify remove api PostApi

? Are you sure you want to delete the resource? This action deletes all files related to this resource from the backend
directory. Yes
✅ Successfully removed resource```

```amplify api update
? Select from one of the below mentioned services: REST
Only one option for [Select the REST API you want to update:]. Selecting [PostsApi].
√ What would you like to do? · Add another path
√ Provide a path (e.g., /book/{isbn}): · /posts/{postId}
√ The path /posts/{postId} overlaps with /posts. Users authorized to access /posts will also have access to /posts/{postId}. Are you sure you want to continue? (y/N) · yes

√ Choose a Lambda source · Use a Lambda function already added in the current Amplify project
Only one option for [Choose the Lambda function to invoke by this path]. Selecting [PostsHandle].
√ Restrict API access? (Y/n) · no
√ Do you want to add another path? (y/N) · no
✅ Successfully updated resource```

```amplify push```
tiny ingot
#

Why are you creating one post handler for /posts and a second post handler for /posts/{postId}?

craggy nest
#

@tiny ingot Probably, I some confused you. At the end, I left only PostsApi and PostsHandle

tiny ingot
#

If the purpose of this is to test it out and see how it works, I'd suggest doing an amplify delete and start from the beginning. Because there could be something hanging around from the addition and removals of functions and api's

#

In general with express. You would create the path for /posts. then in the handler have two routes GET /posts GET /posts/:id

#

So, just one api and just one path and just one handler.

craggy nest
#

Got it... Okay, thanks! I'll try this approach and write down the result

tiny ingot
#

If you don't have much experience of express routes, there's plenty of tutorials online.

#

Happy hunting!

craggy nest
#

@tiny ingot I'm sorry... could you please give the example of tutorial with adding two routes?
What's I done:

amplify init
amplify add api
>>> REST
>>> PostsApi
>>> /posts
>>> PostsHandle
>>> NodeJS
>>> Hello world
>>> without advanced settings configuration
>>> without editing the local lambda function now
>>> Restring API access? no
>>> Do you want to add another path? No
amplify push```
=> Deployment completed.

```amplify add api
? Select from one of the below mentioned services: REST
√ Would you like to add a new path to an existing REST API: (y/N) · yes
Only one option for [Select the REST API you want to update:]. Selecting [PostsApi].
√ What would you like to do? · Add another path
√ Provide a path (e.g., /book/{isbn}): · /posts/{postId}
√ The path /posts/{postId} overlaps with /posts. Users authorized to access /posts will also have access to /posts/{postId}. Are you sure you want to continue? (y/N) · yes

√ Choose a Lambda source · Use a Lambda function already added in the current Amplify project
Only one option for [Choose the Lambda function to invoke by this path]. Selecting [PostsHandle].
√ Restrict API access? (Y/n) · no
√ Do you want to add another path? (y/N) · no
✅ Successfully added resource PostsApi locally

amplify push```
=> error...

I found the documentation how to add the one route, but not found the documentation how to correctly add the subpath... @tiny ingot Could you please give the link for relative tutorial?
Thanks in advance!
tiny ingot
#

You don't need to do the second add api.

#

Start from scratch again but when you select the function template instead of 'hello world' select 'Serverless express function (Integration with Amazon API Gateway)'

#

In the created function you will see how the different routes are handled.

#

As far as tutorials... this guy is really good. though the node express tutorial is 5 years old. it will teach you the essentials

craggy nest
#

@tiny ingot Thanks a lot for the option with Serverless express function!
I have an experience with ExpressJS and customized these two routes!
Also, thanks for the ExpressJS tutorial!

tiny ingot
#

Great! Enjoy the coding 🙂

livid boneBOT
#

✅ - Can't add additional route