How the Lumen framework registers multiple routes (or responds to all http requests)

Source: Internet
Author: User
I am trying to use Lumen to develop an interface. After tossing it down, I found that the server used the GET Method Request interface for the first URL verification, and then used the POST method access interface. So I want to register the route as a response to GET and POST requests: I checked the laravel5 text... I am trying to use Lumen to develop an interface. After tossing it down, I found that the server used the GET Method Request interface for the first URL verification, and then used the POST method access interface.

Therefore, I want to register the route as a response to GET and POST requests:

I checked the laravel 5 Documentation and matched the route for multiple requests:

Route::match(['get', 'post'], '/', function(){    return 'Hello World';});

Register as responding to all requests:

Route::any('foo', function(){    return 'Hello World';});

Then I try to set the original$app->get()And$app->post()Change$app->any(), Reproduction error:
Fatal error: Call to undefined method Laravel \ Lumen \ Application: any ()

Therefore, may I ask:In the Lumen framework, what should I do if I want to register a path as a response to all requests (or respond to both POST and GET requests?

Reply content:

I am trying to use Lumen to develop an interface. After tossing it down, I found that the server used the GET Method Request interface for the first URL verification, and then used the POST method access interface.

Therefore, I want to register the route as a response to GET and POST requests:

I checked the laravel 5 Documentation and matched the route for multiple requests:

Route::match(['get', 'post'], '/', function(){    return 'Hello World';});

Register as responding to all requests:

Route::any('foo', function(){    return 'Hello World';});

Then I try to set the original$app->get()And$app->post()Change$app->any(), Reproduction error:
Fatal error: Call to undefined method Laravel \ Lumen \ Application: any ()

Therefore, may I ask:In the Lumen framework, what should I do if I want to register a path as a response to all requests (or respond to both POST and GET requests?

Copy A get post and write each time.
Or the Function name does not contain the request method. get post is defined once in the route.

You can extend the Application class and write a method map by yourself.


  addRoute($method, $uri, $action);        }    }}

Then in routes. php

$app->map(['GET','POST'], 'foo', function() {    return 'Hello World';});

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.