H_MZ 2015-10-10 20:56 采纳率: 0%
浏览 25

在Laravel中制作API

I am a laravel beginner. I am building a PHP backend using laravel that will serve multiple platforms. I want to make an api that multiple platforms can use. This is what I am thinking of doing:

my api can be accessed like this: URL.com/api/v1/login (this responds in JSON)

and , if it a web version, login can be accessed from URL.com/login.This should display a form which will send an AJAX request to

URL.com/api/v1/login

I am thinking of setting up different routes for this. something like :

routes::post(api/v1/login,"whatever controller")

and

routes::get(login,"login_controller_which_will_send_ajax_requests_to the_above_controller")

I would like to ask something like this is recommended. if not, what is a better way to implement this

  • 写回答

2条回答 默认 最新

  • 10.24 2015-10-10 21:38
    关注

    Suppose the multiple platforms you mentioned could be grouped as the website and mobile apps.

    The recommendation is to build them separately: build the website like what you would do traditionally, and another api merely for mobile apps.

    The reason is simple: For the website, you can use sessions to store user login status, but for mobile app, you need to use something like json web token to verify the user. It is going to be messy and hard to maintain if they share routes and actions.

    Of course there are exceptions. If you built website as a web app using some JS framework like AngularJS, you may just build the api and serve them all.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题