1
1
/**
2
2
* @author Jason Dobry <[email protected] >
3
3
* @file js-data-http.js
4
- * @version 0.3 .0 - Homepage <http://www.js-data.iojs-data-http/>
4
+ * @version 0.4 .0 - Homepage <http://www.js-data.iojs-data-http/>
5
5
* @copyright (c) 2014 Jason Dobry
6
6
* @license MIT <https://github.com/js-data/js-data-http/blob/master/LICENSE>
7
7
*
@@ -1310,6 +1310,8 @@ defaultsPrototype.queryTransform = function (resourceName, params) {
1310
1310
return params ;
1311
1311
} ;
1312
1312
1313
+ defaultsPrototype . basePath = '' ;
1314
+
1313
1315
defaultsPrototype . httpConfig = { } ;
1314
1316
1315
1317
defaultsPrototype . log = console ? console . log : function ( ) {
@@ -1330,6 +1332,14 @@ function DSHttpAdapter(options) {
1330
1332
1331
1333
var dsHttpAdapterPrototype = DSHttpAdapter . prototype ;
1332
1334
1335
+ dsHttpAdapterPrototype . getIdPath = function ( resourceConfig , options , id ) {
1336
+ return makePath ( options . basePath || this . defaults . basePath || resourceConfig . basePath , resourceConfig . getEndpoint ( id , options ) , id ) ;
1337
+ } ;
1338
+
1339
+ dsHttpAdapterPrototype . getAllPath = function ( resourceConfig , options ) {
1340
+ return makePath ( options . basePath || this . defaults . basePath || resourceConfig . basePath , resourceConfig . getEndpoint ( null , options ) ) ;
1341
+ } ;
1342
+
1333
1343
dsHttpAdapterPrototype . HTTP = function ( config ) {
1334
1344
var _this = this ;
1335
1345
var start = new Date ( ) . getTime ( ) ;
@@ -1390,7 +1400,7 @@ dsHttpAdapterPrototype.find = function (resourceConfig, id, options) {
1390
1400
var _this = this ;
1391
1401
options = options || { } ;
1392
1402
return _this . GET (
1393
- makePath ( options . baseUrl || resourceConfig . baseUrl , resourceConfig . getEndpoint ( id , options ) , id ) ,
1403
+ _this . getIdPath ( resourceConfig , options , id ) ,
1394
1404
options
1395
1405
) . then ( function ( data ) {
1396
1406
return ( options . deserialize ? options . deserialize : _this . defaults . deserialize ) ( resourceConfig . name , data ) ;
@@ -1406,7 +1416,7 @@ dsHttpAdapterPrototype.findAll = function (resourceConfig, params, options) {
1406
1416
deepMixIn ( options . params , params ) ;
1407
1417
}
1408
1418
return _this . GET (
1409
- makePath ( options . baseUrl || resourceConfig . baseUrl , resourceConfig . getEndpoint ( null , options ) ) ,
1419
+ _this . getAllPath ( resourceConfig , options ) ,
1410
1420
options
1411
1421
) . then ( function ( data ) {
1412
1422
return ( options . deserialize ? options . deserialize : _this . defaults . deserialize ) ( resourceConfig . name , data ) ;
@@ -1417,7 +1427,7 @@ dsHttpAdapterPrototype.create = function (resourceConfig, attrs, options) {
1417
1427
var _this = this ;
1418
1428
options = options || { } ;
1419
1429
return _this . POST (
1420
- makePath ( options . baseUrl || resourceConfig . baseUrl , resourceConfig . getEndpoint ( attrs , options ) ) ,
1430
+ makePath ( options . basePath || this . defaults . basePath || resourceConfig . basePath , resourceConfig . getEndpoint ( attrs , options ) ) ,
1421
1431
options . serialize ? options . serialize ( resourceConfig . name , attrs ) : _this . defaults . serialize ( resourceConfig . name , attrs ) ,
1422
1432
options
1423
1433
) . then ( function ( data ) {
@@ -1429,7 +1439,7 @@ dsHttpAdapterPrototype.update = function (resourceConfig, id, attrs, options) {
1429
1439
var _this = this ;
1430
1440
options = options || { } ;
1431
1441
return _this . PUT (
1432
- makePath ( options . baseUrl || resourceConfig . baseUrl , resourceConfig . getEndpoint ( id , options ) , id ) ,
1442
+ _this . getIdPath ( resourceConfig , options , id ) ,
1433
1443
options . serialize ? options . serialize ( resourceConfig . name , attrs ) : _this . defaults . serialize ( resourceConfig . name , attrs ) ,
1434
1444
options
1435
1445
) . then ( function ( data ) {
@@ -1446,7 +1456,7 @@ dsHttpAdapterPrototype.updateAll = function (resourceConfig, attrs, params, opti
1446
1456
deepMixIn ( options . params , params ) ;
1447
1457
}
1448
1458
return this . PUT (
1449
- makePath ( options . baseUrl || resourceConfig . baseUrl , resourceConfig . getEndpoint ( null , options ) ) ,
1459
+ _this . getAllPath ( resourceConfig , options ) ,
1450
1460
options . serialize ? options . serialize ( resourceConfig . name , attrs ) : _this . defaults . serialize ( resourceConfig . name , attrs ) ,
1451
1461
options
1452
1462
) . then ( function ( data ) {
@@ -1458,7 +1468,7 @@ dsHttpAdapterPrototype.destroy = function (resourceConfig, id, options) {
1458
1468
var _this = this ;
1459
1469
options = options || { } ;
1460
1470
return _this . DEL (
1461
- makePath ( options . baseUrl || resourceConfig . baseUrl , resourceConfig . getEndpoint ( id , options ) , id ) ,
1471
+ _this . getIdPath ( resourceConfig , options , id ) ,
1462
1472
options
1463
1473
) . then ( function ( data ) {
1464
1474
return ( options . deserialize ? options . deserialize : _this . defaults . deserialize ) ( resourceConfig . name , data ) ;
@@ -1474,7 +1484,7 @@ dsHttpAdapterPrototype.destroyAll = function (resourceConfig, params, options) {
1474
1484
deepMixIn ( options . params , params ) ;
1475
1485
}
1476
1486
return this . DEL (
1477
- makePath ( options . baseUrl || resourceConfig . baseUrl , resourceConfig . getEndpoint ( null , options ) ) ,
1487
+ _this . getAllPath ( resourceConfig , options ) ,
1478
1488
options
1479
1489
) . then ( function ( data ) {
1480
1490
return ( options . deserialize ? options . deserialize : _this . defaults . deserialize ) ( resourceConfig . name , data ) ;
0 commit comments