Open stepan-romankov opened 10 years ago
Good idea!
I've been thinking about this. How would the tool know to do "http://mydomain.com/mock_data/somting/5.get.json" instead of "http://mydomain.com/mock_data/somting/5/get.json" ?
Is it because it's a number? Is it a guarantee that numbers are always id's? It might be confusing with special cases like that. So I think that either the last thing after a / is either a folder or the filename. I choose filename because if you want /6 and /7 it's easier to create and less folders.
What do you think @stepan-romankov ?
Sorry @seriema, seems to be misunderstanding. First of all list of url should be http://mydomain.com/api/somting/ (with finishing /)
I mean it will be good to have http://mydomain.com/mock_data/somting/get.json instead of http://mydomain.com/mock_data/somting.get.json so the list of something will be in the same deirectory with item of something.
So if what I say makes sense that final / should not be cleaned up during URL replacement. line 142
if (newPath[newPath.length - 1] === '/') {
newPath = newPath.slice(0, -1);
}
or at least it can be optional
Also what about replacing HTTP METHOD for all requests with GET? It will allow to mock POST requests
Exactly, I was just pointing out an inconsistency in your samples.
So "http://mydomain.com/api/somting" will become "http://mydomain.com/api/somting/get.json" just like your example.
And "http://mydomain.com/api/somting/5" will become "http://mydomain.com/api/somting/5/get.json" and not "http://mydomain.com/mock_data/somting/5.get.json" like your example
See what I mean? It's hard for the code to know if the last part of the URL should be included in the name or not.
Is it not working with POST requests? If so, could you open a new issue and explain a bit more? Thanks!
Finally how I see it should be: http://mydomain.com/api/somting -> http://mydomain.com/mock_data/somting.get.json http://mydomain.com/api/somting/ -> http://mydomain.com/mock_data/somting/get.json http://mydomain.com/api/somting/5 -> http://mydomain.com/mock_data/somting/5.get.json http://mydomain.com/api/somting/5/ -> http://mydomain.com/mock_data/somting/5/get.json
So it should take into account last "/" but not cut it all the time. In this case list resources can have / at the end of url and items will not have such.
Does it makes sense?
I see! I wonder if most developers aren't a bit sloppy with ending '/'? I know I am. Not being consistent with that would make the interceptor go try different paths which would confuse the developer.
I could agree on either or. Either it always does as currently, or it always turns the last parameter into a folder. This would be easy and could be configured in the config()
call.
Is that an OK compromise? Or that wouldn't really help at all?
Thanks for your reply! I think "stripTrailingSlash" in config() options could be more then enough to go.
Glad to have your feedback :)
Just so I'm sure, "stripTrailingSlash" would be my compromise to your suggestion then? I'll probably call it something else as what it's actually doing is always use folders.
Agree with you!
Awesome! I'll add this to my todo-list. ^^
Is it it possible to add an option to configure url for mock data requests. Lets say that we have following real REST urls : "http://mydomain.com/api/somting" - a list of something "http://mydomain.com/api/somting/5" - an item
then mocked path's for them will be : "http://mydomain.com/mock_data/somting.get.json" "http://mydomain.com/mock_data/somting/5.get.json"
From my point of view it will be more clean to have all mock data for an entity in the same directory: "http://mydomain.com/mock_data/somting/get.json" - a mocked list of something "http://mydomain.com/mock_data/somting/5.get.json" - - a mocked item
Would be very appreciate you if you add such option.