Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move trailing slashes config #67

Merged
merged 1 commit into from
Feb 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions addon/adapters/drf.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default DS.RESTAdapter.extend({
throw new Ember.Error(error);
}
},
addTrailingSlashes: true,

/**
* Determine the pathname for a given type.
Expand All @@ -53,7 +54,7 @@ export default DS.RESTAdapter.extend({
* If an ID is specified, it adds the ID to the path generated for
* the type, separated by a `/`.
*
* If the adapter has the property `add_trailing_slashes` set to
* If the adapter has the property `addTrailingSlashes` set to
* true, a trailing slash will be appended to the result.
*
* @method buildURL
Expand All @@ -64,7 +65,7 @@ export default DS.RESTAdapter.extend({
*/
buildURL: function(type, id, record) {
var url = this._super(type, id, record);
if (this.get('add_trailing_slashes')) {
if (this.get('addTrailingSlashes')) {
if (url.charAt(url.length - 1) !== '/') {
url += '/';
}
Expand Down
4 changes: 0 additions & 4 deletions app/adapters/drf.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,5 @@ export default DRFAdapter.extend({

namespace: function() {
return ENV.APP.API_NAMESPACE;
}.property(),

add_trailing_slashes: function() {
return ENV.APP.API_ADD_TRAILING_SLASHES;
}.property()
});
8 changes: 0 additions & 8 deletions docs/configuring.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ The URL prefix (namespace) for your API. In other words, if you set this to my-
API requests will look like /my-api/v1/users/56/, or similar.


## API_ADD_TRAILING_SLASHES

**Default:** `true`

Whether to append a trailing slash to API URL endpoints.


## Example

```js
Expand All @@ -33,7 +26,6 @@ Whether to append a trailing slash to API URL endpoints.
module.exports = function(environment) {
var ENV = {
APP: {
API_ADD_TRAILING_SLASHES: false
}
};

Expand Down
28 changes: 28 additions & 0 deletions docs/trailing-slashes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Trailing Slashes


By default, Django REST Framework adds trailing slashes to its generated URLs.
EDA is set up to handle this, however, if you have decided to opt out of
trailing slashes, you will need to extend the adapter with this configuration.

e.g., if you have set up a router in DRF that is instantiated like this:

```python
from rest_framework import routers


router = routers.DefaultRouter(trailing_slash=False)
```

then you will need to [extend](extending.md) the adapter and switch off
`addTrailingSlashes` in `app/adapters/application.js`:

```js
// app/adapters/application.js

import DRFAdapter from './drf';

export default DRFAdapter.extend({
addTrailingSlashes: false
});
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pages:
- ['index.md', 'Introduction']
- ['configuring.md']
- ['extending.md']
- ['trailing-slashes.md']
- ['embedded-records.md']
- ['pagination.md']
- ['contributing.md']
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/adapters/drf-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ test('buildURL', function() {

test('buildURL - no trailing slashes', function() {
var adapter = this.subject();
adapter.set('add_trailing_slashes', false);
adapter.set('addTrailingSlashes', false);
equal(adapter.buildURL('Animal', 5, null), 'test-host/test-api/animals/5');
equal(adapter.buildURL('FurryAnimals', 5, null), 'test-host/test-api/furry-animals/5');
});
Expand Down