-
Notifications
You must be signed in to change notification settings - Fork 8
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
the ability to return headers in mock requests #63
Comments
Hmm good question. You can set it to return a status code instead of data. The tricky part here is how you'd set the headers, as the idea is for simple .json files to replace the real API when mocking. Maybe some "meta" object in the .json? Any suggestions on how you'd like to set the headers? |
our thought was a second file endpoint.headers.json that would have an object of headers to be added to the response. A headers object while also possible has a problem if the response it is a list of objects. Which is why we leaned to a second file. if the file exists included it otherwise forget about it. |
Do you always want the exact same headers for every call, without exceptions? That'd be easy enough. The file could be in the API root path. I'm thinking that maybe such things as setting defaults for all calls would be best to do during |
for our use case it would be a different response for each call. basically saying where to go next on success. for example:
or The philosophy is defined here in this article. http://farazdagi.com/blog/2014/rest-long-running-jobs/ We do not object to a way to set it globally that could come in handy too if we want to do something with authentication logic and such, but this is our main use case in this instance. |
Interesting scenario. From your example and reading that article I understand it as I'm not sure I understand the downside of having the header in the same mock JSON as the response? You mentioned a list of objects, but currently we can only map one API path to one physical file, so if you want to mock a lot of students it'd have to be a lot of JSON files. Solving that could be another feature. Sorry if I'm dense, but maybe you can post an example of how you imagine the contents of a headers.json file so I can better understand why it can't just be a special property on the regular response .json? |
Sounds about right, though I would make the follow option an optional parameter. The auto redirect would only be helpful if the status code returned is in the 300 range, a location header with a different status code could be for other purposes. I understand what you are saying about mapping to one file. Headers is something for many other purposes other than our use case, so I know for the integrity of the project, it is useful not to limit yourself to our use case. As a result if the event the endpoint returns an array of objects such as: [
{
"enrollmentId": 1,
"name": "Daniel Bedoya",
"sid": null,
"sectionId": null,
"percentGrade": 88.58,
"letterGrade": "B",
"readyToPost": true
},
{
"enrollmentId": 1,
"name": "Daniel Bedoya",
"sid": "L1234567",
"sectionId": "CNVS0997_01_1202",
"percentGrade": 88.58,
"letterGrade": "B",
"readyToPost": false
}
] then a headers object would not be possible. So our thought to cover all cases would be that the headers.json file would just be an object of headers like it is represented in the $http response object. This could be expanded in the future so each response can define a status code then apps can mock failed responses as well. {
"status": 200,
"headers": {
"Last-Modified": "Tue, 15 Nov 201512:45:26 GMT",
"Location": "http://myurl.com/rest/students/42",
"Authentication" : "Bearer 123jighsd08g79sdf8jsidjf"
}
} Another option would be to define the whole response in the endpoint.get.json and then apimock could manipulate the response object in the interceptor. {
"headers": {
"Last-Modified": "Tue, 15 Nov 201512:45:26 GMT",
"Location": "http://myurl.com/rest/students/42",
"Authentication" : "Bearer 123jighsd08g79sdf8jsidjf"
},
"status": 200,
"data": [
{
"enrollmentId": 1,
"name": "Daniel Bedoya",
"sid": null
},
{
"enrollmentId": 1,
"name": "Daniel Bedoya",
"sid": "L1234567"
}
]
} |
any progress in this? |
@pauldburton sorry, not really. angular-apimock is pretty simplistic and will just return one .json file for one api request. Your enrolment example pointed out that angular-apimock would have to require an object and not support pure arrays. One option would be to simply not support headers on pure arrays, and requiring a more complex object like you posted for custom responses. So having a separate headers file does make sense in keeping the data json simpler, but it would add an invisible dependency between files and "didn't you read the documentation?" scenarios I'd like to avoid. If you'd like to make a PR then that'd help me out a lot. |
We have a feature where we make a queue request and it returns a header providing the location of the progress endpoint. This endpoint returns another header with the results endpoint once the processing is completed.
We need the ability to assign those headers to allow our apimock functionality to work again. Would this be possible?
The text was updated successfully, but these errors were encountered: