Skip to content

Commit a9f7f90

Browse files
authored
Merge pull request #12 from vilkasgroup/AddSupportForQueryParameters
Added support for custom query parameters.
2 parents 2ac00da + 93ae04d commit a9f7f90

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/restClient.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export default (apiUrl, httpClient = fetchJsonWithToken) => {
5555
// specify reverse orderings by prefixing the field name with '-'
5656
const order = params.sort.order == 'DESC' ? '-' : '';
5757
const field = params.sort.field || 'id';
58+
const queryParams = params.queryParams || '';
5859
const query = {
5960
...flattenObject(params.filter),
6061
ordering: order + field,
@@ -64,6 +65,12 @@ export default (apiUrl, httpClient = fetchJsonWithToken) => {
6465
offset: (page - 1) * perPage
6566
};
6667
url = `${apiUrl}/${resource}/?${stringify(query)}`;
68+
69+
// If there's extra query parameters given, add them to the url
70+
if(queryParams) {
71+
url += `&${stringify(queryParams)}`;
72+
}
73+
6774
options.method = 'GET';
6875
break;
6976
}
@@ -130,7 +137,7 @@ export default (apiUrl, httpClient = fetchJsonWithToken) => {
130137
const convertHTTPErrorToREST = (httpError) => {
131138
const { status, body, name } = httpError;
132139

133-
if (typeof (body) === 'object' && body.detail) {
140+
if (typeof (body) === 'object' && body.detail) {
134141
httpError.message = body.detail;
135142
}
136143
return Promise.reject(httpError);

0 commit comments

Comments
 (0)