<p>Quite a simple solution set the criteria to uri and you just pass the endpoint as is as a catch all.</p>

<pre><code>$normal =  preg_replace('/.json/', '', craft()-&gt;request-&gt;path);
return [
        'endpoints' =&gt; [
            craft()-&gt;request-&gt;path =&gt; [
                'elementType' =&gt; 'Entry',
                'criteria' =&gt; ['uri' =&gt; $normal],
                'first' =&gt; true,
                'transformer' =&gt; new DetailTransformer(),
            ],
        ]
    ];
</code></pre>

CC BY-SA 3.0
2016-05-23T11:41:51.713Z
2016-05-23T11:41:51.713Z
Mark Watson
<p>Would like to be able to handle requests for structured requests so that it may be handled in one endpoint </p>

<pre><code>    about.json
    about/the-team.json
    about/contact/london.json
</code></pre>

<p>Presumably a form of regex would be required for this to work?
Contemplating:</p>

<pre><code>    pages/about.json
    pages/about/the-team.json
    pages/about/contact/london.json
</code></pre>

<p>All though how would you prepare a check for 'pages' as your first node?</p>

<p>Currently have this but not fees able. </p>

<pre><code>   '&lt;slug:{slug}&gt;*.json' =&gt; function($slug) {
</code></pre>

<p>thanks</p>

<routing><plugin-elementapi>
ElementAPI endpoint routing syntax for multi-level structure
# ElementAPI endpoint routing syntax for multi-level structure

(Asked by: username_0 on 2016-05-04)

Would like to be able to handle requests for structured requests so that it may be handled in one endpoint 
    about.json
    about/the-team.json
    about/contact/london.json

Presumably a form of regex would be required for this to work?
Contemplating:
    pages/about.json
    pages/about/the-team.json
    pages/about/contact/london.json

All though how would you prepare a check for 'pages' as your first node?
Currently have this but not fees able. 
   '*.json' => function($slug) {

thanks

**Tags:** routing, plugin-elementapi


---

## 1 answers

### Answer by username_0 on 2016-05-23. Score: 2 | Accepted answer

Quite a simple solution set the criteria to uri and you just pass the endpoint as is as a catch all.
$normal =  preg_replace('/.json/', '', craft()->request->path);
return [
        'endpoints' => [
            craft()->request->path => [
                'elementType' => 'Entry',
                'criteria' => ['uri' => $normal],
                'first' => true,
                'transformer' => new DetailTransformer(),
            ],
        ]
    ];


---

