2016-12-13 09:46
采纳率: 100%
浏览 1.5k

如何访问Laravel API路由?

我刚刚在本地主机目录中创建了一个新的Laravel项目,并在 api.php 文件中创建了Laravel路由。

Route::post('/home', 'HomeAPI@index');

当我尝试从 Postman 向链接localhost/home发送发帖请求时,出现以下错误:

Sorry, the page you are looking for could not be found.

1/1 NotFoundHttpException in RouteCollection.php line 161:

那我该如何访问我的 /home路由?

图片转代码服务由CSDN问答提供 功能建议

我刚刚在localhost目录中创建了一个新的Laravel项目,并在 api.php中创建了一个Laravel路由 文件。

  Route :: post('/ home','HomeAPI @ index'); 
 \  n 

但是,当我尝试从邮递员 localhost / home 发送帖子请求时,会出现以下错误: \ n


RouteCollection.php第161行中的1/1 NotFoundHttpException:

如何访问 / home 路由?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douying4203 2016-12-13 09:52

    When trying to access a API route (route mentioned in api.php) from Laravel, just add /api to the link you are trying to access. In this case, your link would be:


    This should solve your problem.

    点赞 评论
  • dongpiao1983 2016-12-13 09:52

    Everything in api.php is under /api so in your case it's localhost/api/home

    点赞 评论

相关推荐 更多相似问题