Skip to content
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

mock url #13

Open
stepan-romankov opened this issue Jun 14, 2014 · 12 comments
Open

mock url #13

stepan-romankov opened this issue Jun 14, 2014 · 12 comments
Assignees
Milestone

Comments

@stepan-romankov
Copy link

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.

@seriema
Copy link
Owner

seriema commented Jun 21, 2014

Good idea!

@seriema
Copy link
Owner

seriema commented Aug 7, 2014

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 ?

@stepan-romankov
Copy link
Author

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

@stepan-romankov
Copy link
Author

Also what about replacing HTTP METHOD for all requests with GET? It will allow to mock POST requests

@seriema
Copy link
Owner

seriema commented Aug 7, 2014

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.

@seriema
Copy link
Owner

seriema commented Aug 7, 2014

Is it not working with POST requests? If so, could you open a new issue and explain a bit more? Thanks!

@stepan-romankov
Copy link
Author

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?

@seriema
Copy link
Owner

seriema commented Aug 8, 2014

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?

@stepan-romankov
Copy link
Author

Thanks for your reply!
I think "stripTrailingSlash" in config() options could be more then enough to go.

@seriema
Copy link
Owner

seriema commented Aug 8, 2014

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.

@stepan-romankov
Copy link
Author

Agree with you!

@seriema
Copy link
Owner

seriema commented Aug 8, 2014

Awesome! I'll add this to my todo-list. ^^

@seriema seriema added this to the 0.2.0 milestone Aug 8, 2014
@seriema seriema self-assigned this Aug 8, 2014
@seriema seriema modified the milestones: 0.3.0, 0.2.0 Sep 13, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants