在各种公共方法都设计好,软件安装成功的条件下

routes/web.php中路由信息如下

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/ Route::get('/index', 'Api\BannerController@index'); //后台登录操作

app/Http/ontollers/Api/BannerController.php中代码如下

<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Http\Controllers\ApiController;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\Session;
use Validator; class BannerController extends ApiController
{
public function index(Request $request){
$validator=Validator::make($request->all(),[
'token'=>'required|string',
'type'=>'required|int'
],[
'token.required'=>'token为空',
'type.required'=>'type为空',
'type.int'=>'type字段仅支持整形'
]
);
if($validator->fails()){
return returnJson('400','sb',$validator->errors());
}
$info=DB::table('admin')->get();
return json_encode(['code'=>'10200','message'=>'cg','data'=>$info[0]]);
} }

网址:http://localhost/ay/public/index.php/index?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MX0.eR3VWi_o8n_dMcrzcy3nIEeQ2Rk96hX0O8UjW33JQPM&type=1

例子二:

web.php中路由为

Route::any('/test/show','UserController@show');

Controllers/UserController.php中代码为

<?php
/**
* Created by PhpStorm.
* User: liuyanjie
* Date: 2018/12/9
* Time: 11:48
*/ namespace App\Http\Controllers; use App\Http\Controllers\Controller;
use Illuminate\Http\Request; class UserController extends Controller
{
public function show(Request $request)
{
$username=$request->get('username');
return $username;
}
}

访问http://localhost/laravel57/public/index.php//test/show?username=aaa

便可得到如下结果

例子三:

web.php中路由为

 Route::any('/test/hello',function (){
return 'This is a request from any HTTP verb';
});

然后访问http://localhost/laravel57/public/index.php//test/hello

便可得到

例子四:

web.php中路由为

Route::any('/test/show','UserController@show');

Controllers/UserController.php中代码为

<?php
/**
* Created by PhpStorm.
* User: liuyanjie
* Date: 2018/12/9
* Time: 11:48
*/ namespace App\Http\Controllers; use App\Http\Controllers\Controller;
use Illuminate\Http\Request; class UserController extends Controller
{
public function show(Request $request)
{
$username=$request->get('username'); return view('index')->with(['info'=>$username]);
}
}

view('index')指向 resources/views/index.blade.php  ,向该文件传递 $info这个参数

index.blade.php 中的代码为:

{{ $info }}

这样便可以将参数进行显示。

访问http://localhost/laravel57/public/index.php//test/show?username=aaa

可得到

例子五:访问数据库

路由

Route::any('/test/show','UserController@show');

控制器:

<?php
/**
* Created by PhpStorm.
* User: liuyanjie
* Date: 2018/12/9
* Time: 11:48
*/ namespace App\Http\Controllers; use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB; class UserController extends Controller
{
public function show(Request $request)
{
// $username=$request->get('username');
$info=DB::table('admin')->get();
return json_encode(['code'=>'10200','message'=>'cg','data'=>$info[0]]);
}
}

laravel接口设计的更多相关文章

  1. API接口设计

    1.场景描述 比如说我们要做一款APP,需要通过api接口给app提供数据.假设我们是做商城,比如我们卖书的.我们可以想象下这个APP大概有哪些内容: 1)首页:banner区域(可以是一些热门书籍的 ...

  2. 数据仓储之DLL层接口设计

    一.接口设计 1.1. IBaseRepository.cs public interface IBaseRepository<T> { T Add(T entity); bool Upd ...

  3. RESTful接口设计原则/最佳实践(学习笔记)

    RESTful接口设计原则/最佳实践(学习笔记) 原文地址:http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api 1 ...

  4. Web API接口设计经验总结

    在Web API接口的开发过程中,我们可能会碰到各种各样的问题,我在前面两篇随笔<Web API应用架构在Winform混合框架中的应用(1)>.<Web API应用架构在Winfo ...

  5. Verilog学习笔记简单功能实现(七)...............接口设计(并行输入串行输出)

    利用状态机实现比较复杂的接口设计: 这是一个将并行数据转换为串行输出的变换器,利用双向总线输出.这是由EEPROM读写器的缩减得到的,首先对I2C总线特征介绍: I2C总线(inter integra ...

  6. 优秀的API接口设计原则及方法(转)

    一旦API发生变化,就可能对相关的调用者带来巨大的代价,用户需要排查所有调用的代码,需要调整所有与之相关的部分,这些工作对他们来说都是额外的.如果辛辛苦苦完成这些以后,还发现了相关的bug,那对用户的 ...

  7. atitit.基于http json api 接口设计 最佳实践 总结o7

    atitit.基于http  json  api 接口设计 最佳实践 总结o7 1. 需求:::服务器and android 端接口通讯 2 2. 接口开发的要点 2 2.1. 普通参数 meth,p ...

  8. App接口设计

    关于APP接口设计 http://blog.csdn.net/gebitan505/article/details/37924711/

  9. App接口设计原则-b

    1.记住密码不是真的让你记住密码,这里仅仅指的是一种自动登录的手段.不管在任何地方,明文存储的密码都是安全隐患,是必须尽量避免的.你可以采用某种方式对用户名.密码以及时间戳(重要)进行签名,再次登录时 ...

随机推荐

  1. OpenCL C

    OpenCL C OpenCL  简介 opencl C是ISO C99的一个扩展,主要区别如下: 去除了C99的一些特性,如:标准C99头文件,函数指针,递归,变长数组,和位域 增加了一些特性用于并 ...

  2. java解析注解的简单例子

    代码是根据慕课网的教程写的. 自定义类的注解: package com.immoc.test; import java.lang.annotation.Documented; import java. ...

  3. C#:winform项目在win7,xp32位和64位都能运行

    vs中项目配置管理器活动解决方案平台选择X86平台.

  4. (转)基于MVC4+EasyUI的Web开发框架经验总结(13)--DataGrid控件实现自动适应宽带高度

    http://www.cnblogs.com/wuhuacong/p/4085725.html 在默认情况下,EasyUI的DataGrid好像都没有具备自动宽度的适应功能,一般是指定像素宽度的,但是 ...

  5. Type inference

    Type inference refers to the automatic detection of the data type of an expression in a programming ...

  6. python tips:小整数对象池与字符串intern

    本文为is同一性运算符的详细解释.is用于判断两个对象是否为同一个对象,具体来说是两个对象在内存中的位置是否相同. python为了提高效率,节省内存,在实现上大量使用了缓冲池技术和字符串intern ...

  7. python 字符串模糊匹配 Fuzzywuzzy

    Python提供fuzzywuzzy模块,不仅可用于计算两个字符串之间的相似度,而且还提供排序接口能从大量候选集中找到最相似的句子. (1)安装 pip install fuzzywuzzy (2)接 ...

  8. OSI参考模型(转)

    一.OSI参考模型 自下而上:物理层(物理介质,比特流).数据链路层(网卡.交换机).网络层(IP协议).传输层(TCP/UDP协议).会话层(创建/建立/断开连接).表示层(翻译,编码,压缩,加密) ...

  9. 记Python学习

    上周学的Python,感觉有点忘了,现在回顾一下... 一.Python安装及测试:https://www.cnblogs.com/weven/p/7252917.html 例子: Python自带的 ...

  10. nyoj112-指数运算

    指数运算时间限制:600 ms  |  内存限制:65535 KB难度:2描述写一个程序实现指数运算 X^N.(1<X<10,0<N<20)输入输入包含多行数据 每行数据是两个 ...