Skip to content

Conversation

TimothyBJacobs
Copy link
Member

This is a first try at adding info about modifying responses to include custom links.



## Adding Links to the API Response
WordPress generates a list of links associated with the queried resource to make it easier to navigate to related resources. The `embeddable` attribute controls whether the linked resource appears in the `_embedded` section of the repsonse.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd split the embeddable bit to later on and describe links by themselves first. I'd also probably note something like "links are sent to the client as the _links property of the JSON object, but are stored separately internally from the response data"

) );
```

The link relation MUST be either a [registered link relation from the IANA](https://www.iana.org/assignments/link-relations/link-relations.xhtml) or a URL that is under your control.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

URL -> URI


```php
<?php
$response->add_link( 'author', rest_url( "/wp/v2/users/{$post->post_author}" ), array(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd have these without embeddable for the first examples

- Move embeddable section later. - Make clear you can't access or modify links from the response data directly. - URL → URI
@TimothyBJacobs
Copy link
Member Author

@rmccue Updated.

@TimothyBJacobs
Copy link
Member Author

@rmccue Bumped

Copy link
Contributor

@kadamwhite kadamwhite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use some copy edits for reading flow, and the curie registration example needs to show the actual add_filter call. But some docs are better than none, so I'm going to go ahead and merge this as-is; thank you for your contribution!


```php
<?php
function my_plugin_prefix_register_curie( $curies ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a line in the example showing the actual filter registration.

@kadamwhite kadamwhite merged commit 6fd1e27 into WP-API:master May 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants