Skip to content

Commit 80e342d

Browse files
committed
Merge pull request #73 from WP-API/add-extension-discovery
Add extension discovery
2 parents a6eeed8 + db0839b commit 80e342d

File tree

2 files changed

+66
-3
lines changed

2 files changed

+66
-3
lines changed

assets/styles/style.scss

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,25 @@ h1, h2, h3, h4, h5, h6 {
142142
font-weight: $header-font-weight;
143143
}
144144

145+
code, pre {
146+
background: rgba(0,0,0,0.04);
147+
}
148+
145149
code {
146150
font-family: $code-font-family;
147151
font-size: 0.8em;
152+
padding: 2px 0.4em;
148153
}
149154

150155
pre {
151156
max-width: 100%;
152157
overflow: auto;
153-
background: rgba(0,0,0,0.04);
154158
padding: 1.8em 1em;
159+
160+
code {
161+
background: transparent;
162+
padding: 0;
163+
}
155164
}
156165

157166
.secondary pre {

guide/discovery/index.md

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,59 @@ for the options for specific authentication methods.
163163
Extension Discovery
164164
-------------------
165165

166-
The REST API currently doesn't support full extension discovery, but it will
167-
soon. :)
166+
Once you've discovered the API, the next step is check what the API supports.
167+
The index of the API exposes the `namespaces` item, which contains the
168+
extensions to the API that are supported.
169+
170+
For regular WordPress (4.4) sites, only the base API infrastructure is
171+
available, not the full API with endpoints. This also includes the oEmbed
172+
endpoints:
173+
174+
```json
175+
{
176+
"name": "Example WordPress Site",
177+
"namespaces": [
178+
"oembed/1.0/"
179+
]
180+
}
181+
```
182+
183+
Sites with the full API available (i.e. with the REST API plugin installed) will
184+
have the `wp/v2` item in `namespaces` as well:
185+
186+
```json
187+
{
188+
"name": "Example WordPress Site",
189+
"namespaces": [
190+
"wp/v2",
191+
"oembed/1.0/"
192+
]
193+
}
194+
```
195+
196+
Before attempting to use any of the core endpoints, you should be sure to check
197+
that the API is supported by checking for `wp/v2` support. WordPress 4.4 will
198+
enable the API infrastructure for all sites, but will **not** include the core
199+
endpoints under `wp/v2`.
200+
201+
This same mechanism can be used for detecting support for any plugins that
202+
support the REST API. For example, take a plugin which registers the
203+
following route:
204+
205+
```php
206+
<?php
207+
register_rest_route( 'testplugin/v1', '/testroute', array( /* ... */ ) );
208+
```
209+
210+
This would add the `testplugin/v1` namespace to the index:
211+
212+
```json
213+
{
214+
"name": "Example WordPress Site",
215+
"namespaces": [
216+
"wp/v2",
217+
"oembed/1.0/",
218+
"testplugin/v1"
219+
]
220+
}
221+
```

0 commit comments

Comments
 (0)