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

Add Resource helper custom path parameter #1068

Merged
merged 6 commits into from Apr 23, 2017

Conversation

rjschie
Copy link
Contributor

@rjschie rjschie commented Apr 22, 2017

This adds in the ability to specify a customized path in the resource helper.

Currently with a server.get() shorthand, the second parameter can be a string for the collection name, if it doesn't match the given path. This PR will bring the server.resource() helper in line with that customizability, although it places this option inside the second parameter's option hash as path.

// given "blog-posts" resource name and a custom path:
server.resource('blog-posts', { path: '/posts' });

// returns shorthands:
server.get('/posts', 'blog-posts');
server.get('/posts/:id', 'blog-posts');
server.post('/posts', 'blog-posts');
server.put('/posts/:id', 'blog-posts');
server.patch('/posts/:id', 'blog-posts');
server.delete('/posts/:id', 'blog-posts');

You could also specify an absolute url as the custom path:

server.resource('blog-posts', { path: 'https://localhost/posts' });

// returns shorthands:
server.get('https://localhost/posts', 'blog-posts');
server.get('https://localhost/posts/:id', 'blog-posts');
server.post('https://localhost/posts', 'blog-posts');
server.put('https://localhost/posts/:id', 'blog-posts');
server.patch('https://localhost/posts/:id', 'blog-posts');
server.delete('https://localhost/posts/:id', 'blog-posts');

@samselikoff
Copy link
Collaborator

nice! I feel like I went a bit heavy on the positional-args-as-API in a few places in Mirage, could we use the options hash and add a path option instead of using second arg?

@rjschie
Copy link
Contributor Author

rjschie commented Apr 22, 2017

Ya definitely! I like that, and it would make things so much simpler. I'll try and get that updated later today.

@rjschie
Copy link
Contributor Author

rjschie commented Apr 22, 2017

Ok, I've update the PR to use the path option. I also thought it might be nice to include the leading / if you define a path, making this open to absolute URL's such as https://localhost/resource-name/, rather than having the leading / hardcoded into the resource handler object map.

@samselikoff
Copy link
Collaborator

Nice work!

@samselikoff samselikoff merged commit 25f8f5b into miragejs:master Apr 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants