greyby
greyby

Reputation: 156

How to custom ember data's restful URL and modify the HTTP method

I use ember data in my project. I know the REST adapter's URL conventions are as follows:

Action  | HTTP Verb| URL
------- | ---------|---------
Find    | GET      | /posts/1
Find All| GET      | /posts
Update  | PUT      | /posts/1
Create  | POST     | /posts
Delete  | DELETE   | /posts/1

But I got a backend's URL like this

Action  | HTTP Verb| URL
------- | ---------|---------
Find    | GET      | /posts/show/1
Find All| GET      | /posts/list
Update  | POST     | /posts/update/1
Create  | POST     | /posts/add
Delete  | POST     | /posts/delete/1

The URL and HTTP verb are both different. I know that I can customize the URL with buildURL (modelName, id, snapshot, requestType, query).I think I can check the requestType and hardcode the URL. I would like to know if there is a elegant way to customize the URL and modify the HTTP method? Thank you.

Ember version 1.12.0 Ember-Cli version 0.2.5 Ember Data version 1.0.0-beta.17

Upvotes: 3

Views: 911

Answers (1)

greyby
greyby

Reputation: 156

I solve this with override the following method in application adapter.

* `find()` * `createRecord()` * `updateRecord()` * `deleteRecord()` * `findAll()` * `findQuery()`

Gist here

Upvotes: 1

Related Questions