umbraco/Umbraco-CMS — pull request #329 by spudstuff (2014-03-23 13:16:50+00:00)
Title: Custom content type support for rest extensions.

This pull request add support for custom content types to rest extensions. Right now the content type is set to either text/xml (returnXml = true in the config) or text/html (returnXml = false in the config).

This is pretty limiting when you want to emit JSON or javascript from a rest extension.

Now you can either use the contentType attribute against each method in the rest config(s), or the ContentType property on the RestExtensionMethod attribute (see examples below).

Note that returnXml still has precedence - if this is set to true then the content type will be text/xml regardless of any contentType attribute. You must set returnXml to false explicitly as it defaults to true.

The changes in this pull request have been tested against:

**restExtensions.config:**
```

```

**BaseRestExtensions.config:**
```

```

**Attributes on methods:**
```
[RestExtensionMethod(ReturnXml = false, ContentType = "application/javascript")]
public static string ServerVars(int nodeId)
{
return "var siteSettings = { \"NodeId\": " + nodeId + " };";
}
```

Note I also added some comments to both rest extension configs to make it clear that BaseRestExtensions.config is the new, improved way.

See also:
* http://our.umbraco.org/forum/developers/api-questions/16682-custom-content-type-from-base-
* http://www.agehrke.com/2011/09/set-content-type-in-umbraco-base-service/