使用 Laravel 的邮箱 REST API。这是一个用于管理内部消息传递的小型电子邮件客户端。我获得了一个基本邮箱 API 的简单原型,其中列出了所提供的消息。每条消息都可以标记为已读,并且您可以存档单条消息。
Ubuntu 16.04 Laravel 5.2 中的 PHP 7.0、mysql 5.6、apache 2.4
=================================================== =================================================== =====================
这是完整的 Laravel 开发框架。所有 REST API 均已实现。您可以更改数据库连接配置。还要根据应用程序文件夹的文档根更改路径。例如。 http://laravel/ [虚拟主机]
Git 将整个文件夹克隆或下载到文档根目录或虚拟主机中。然后从终端运行以下命令: ###php artisan make:migration mail_details###
使用REST客户端来测试API。
从 JSON 文件导入消息 为了使用一些示例消息为数据库做种,提供了一个 JSON 文件,需要将其导入到数据库中。请编写一个任务,可以将此消息导入到数据库 messages_sample.json 中
共享于 /helpdocuments/ 文件夹
消息API 主要任务是为消息构建API。它应该是一个基于 REST 的 API,具有 JSON 格式的有效负载。 API 应支持以下用例。
JSON 请求
网址:http://laravel/api/v1/mailbox/savemessages
JSON 请求
{ "limit" : " 6 " }
网址:http://laravel/api/v1/mailbox
JSON 响应
{ "error" : false , "message" : " All mail fetched " , "mails" :{ "total" : 10 , "per_page" : 5 , "current_page" : 1 , "last_page" : 2 , "next_page_url" : " http: // laravel / api / v1 / mailbox?page=2 " , "prev_page_url" : null , "from" : 1 , "to" : 5 , "data" :[{ "mail_detail_id" : 21 , "mail_detail_uid" : 26 , "mail_detail_sender" : " Jane Austen " , "mail_detail_subject" : " treasure-hunter " , "mail_detail_message" : " The story is about a treasure-hunter and a treasure-hunter who is constantly annoyed by a misguided duke. It takes place on a forest planet in a galaxy-spanning commonwealth. The critical element of the story is a door being opened " , "mail_detail_time_sent" : " 2016-02-29 07:20:27 " , "mail_detail_read" : 0 , "mail_detail_archive" : 0 , "created_at" : " 2017-01-06 16:19:46 " , "updated_at" : " 2017-01-06 16:19:46 " } ..... ]}}
JSON 请求
{ "limit" : " 5 " }
网址:http://laravel/api/v1/mailbox/listarchive
JSON 响应
{ "error" : false , "message" : " Archived messages fetch successfully " , "mails" :{ "total" : 2 , "per_page" : 5 , "current_page" : 1 , "last_page" : 1 , "next_page_url" : null , "prev_page_url" : null , "from" : 1 , "to" : 2 , "data" :[{ "mail_detail_id" : 15 , "mail_detail_uid" : 26 , "mail_detail_sender" : " Jane Austen " , "mail_detail_subject" : " treasure-hunter " , "mail_detail_message" : " The story is about a treasure-hunter and a treasure-hunter who is constantly annoyed by a misguided duke. It takes place on a forest planet in a galaxy-spanning commonwealth. The critical element of the story is a door being opened " , "mail_detail_time_sent" : " 2017-01-06 21:27:12 " , "mail_detail_read" : 1 , "mail_detail_archive" : 1 , "created_at" : " 2017-01-06 08:46:25 " , "updated_at" : " 2017-01-06 08:46:25 " } ... ]}}
JSON 请求
{ "id" : " 10 " }
网址:http://laravel/api/v1/mailbox/show
JSON 响应
{ "error" : false , "message" : " Fetched message details successfully " , "mail" :[{ "mail_detail_id" : 10 , "mail_detail_uid" : 21 , "mail_detail_sender" : " Ernest Hemingway " , "mail_detail_subject" : " animals " , "mail_detail_message" : " This is a tale about nihilism. The story is about a combative nuclear engineer who hates animals. It starts in a ghost town on a world of forbidden magic. The story begins with a legal dispute and ends with a holiday celebration. " , "mail_detail_time_sent" : " 2017-01-06 21:42:23 " , "mail_detail_read" : 1 , "mail_detail_archive" : 1 , "created_at" : " 2017-01-06 08:46:25 " , "updated_at" : " 2017-01-06 16:12:23 " }]}
JSON 请求
{ "id" : " 1 " }
网址:http://laravel/api/v1/mailbox/read
JSON 响应
{ "error" : false , "message" : " Mail read updated successfully " }
JSON 请求
{ "id" : " 10 " }
网址:http://laravel/api/v1/mailbox/makearchive
JSON 响应
{ "error" : false , "message" : " Mail arcived updated successfully " }
除了 API 之外,还请提供一个简短的文档,说明如何使用它以及端点如何工作。为简单起见,我们仅使用简单的 HTTP 授权标头。
/tests/ 文件夹中的更多详细信息。
=================================================== =================================================
我在一夜之内就创建了:)。因此,生产版本肯定还有很多改进的空间。少数如下:
基于 Passport / Oauth2 的 API 令牌身份验证方法,用于调用 REST API [https://laravel.com/docs/5.3/passport]
在保存或更新数据之前更多地检查 pvt 方法。例如。在更新到存档之前需要检查它是否已经更新为存档
将整个应用程序制作为 laravel 包/模块
制作了完整的 emial 客户端前端以及左侧选项卡中的不同菜单和右侧选项卡中的详细操作。
通过ajax自动调用API,例如。打开邮件时,它会调用并更新为已读
=================================================== =================================================== =========
其余客户端测试的一些屏幕截图: