Could you please tell me about the app communication between Laravel and andriod?

WBOY
Release: 2016-08-29 08:37:02
Original
813 people have browsed it

May I ask if the communication between Laravel and andriod app can be received directly using $_POST and $_GET, and then echo json_decode(xxx); returns the information? Can this place be placed anywhere? Reply content:

If you do this as the questioner said, then there will be nothing wrong with Laravel :0, wouldn't it be faster if you just create a few php files?


REST API is not as simple as the questioner imagined.


    First of all, since the REST API itself is stateless and does not have Session and Cookie support, how to identify the client's identity and how to save the user's login status are all problems encountered in API development. .

  • So to introduce the TOKEN mechanism, the best solution I know for using the TOKEN mechanism is JWT (JSON WEB TOKEN), and there is already Laravel's third-party JWT component implementation (JWT (Json Web Token) is used in Laravel 5) Implement API-based user authentication
).

    Secondly, before you write the API, your Laravel may have already written a WEB website. Since Laravel’s routes are all in routes.php, write the REST API route into it, which will create a huge routes. Managing .php is a disaster.

  • At the same time, we hope that the API has a unified response structure. All business data is placed under the data attribute. Each response needs to return timestamp and status, so how to achieve it?

<code class="language-json"><span class="p">{</span>
  <span class="nt">"data"</span><span class="p">:</span> <span class="p">[</span>
    <span class="p">{</span>
      <span class="nt">"id"</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
      <span class="nt">"title"</span><span class="p">:</span> <span class="s2">"VIDEO_1"</span><span class="p">,</span>
    <span class="p">},</span>
    <span class="p">{</span>
      <span class="nt">"id"</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span>
      <span class="nt">"title"</span><span class="p">:</span> <span class="s2">"VIDEO_2"</span><span class="p">,</span>
    <span class="p">},</span>
    <span class="p">{</span>
       <span class="err">......</span>
    <span class="p">}</span>
  <span class="p">],</span>
  <span class="nt">"timestamp"</span><span class="p">:</span> <span class="mi">1472200713</span><span class="p">,</span>
  <span class="nt">"status"</span><span class="p">:</span> <span class="mi">200</span>
<span class="p">}</span>
</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template