Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

177
Views
SlimPhp 2 optional route

I'm making an API with PHP Slim 2.

I'm trying to get a JSON of the request which have an obligatory dqaid and optional parameters.

$app->get('/stats/getCrash/dqaid=:dqaid(/appid=:app_id(/reason=:reason(/appvid=:app_version_id(/reasonh=:reason_hash
            (/brand=:brand(/model=:model(/osversion=:os_version(/portal=:portal))))))))',
    function ($dqaid, $app_id = null, $reason = null, $app_version_id = null, $reason_hash = null, $brand = null,
              $model = null, $os_version = null, $portal = null) use ($app) {
    $app->response->setStatus(200);
    $app->response->setBody(json_encode(CrashFilters::createRequest($dqaid, $app_id, $reason, $app_version_id, $reason_hash, $brand,
                                                                    $model, $os_version, $portal)));
    $app->response->headers->set('Content-Type', 'application/json');
});

this works if I put the optional parameters in the right order like this :

localhost:8180/stats/getCrash/dqaid=ff50640713c84a99/appid=229338/reason=150258106

But if I omit one or put them in the wrong order I get an error 404.

I'd like to be able to put only those I want and in the order I want.

Another question : I'd like to be able to access my page like that in the future :

localhost:8180/stats/getCrash?dqaid=ff50640713c84a99&appid=229338&reason=150258106

So using ? and & instead of / in my url.

Where can I set that ?

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!