File tree Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -366,6 +366,59 @@ class Twitter::API < Grape::API
366
366
end
367
367
```
368
368
369
+ ## Remounting
370
+
371
+ You can mount the same endpoints in two different locations using ` RemountableAPI `
372
+
373
+ ``` ruby
374
+ class Voting ::API < Grape ::RemountableAPI
375
+ namespace ' votes' do
376
+ get do
377
+ # Your logic
378
+ end
379
+
380
+ post do
381
+ # Your logic
382
+ end
383
+ end
384
+ end
385
+
386
+ class Post ::API < Grape ::API
387
+ mount Voting ::API
388
+ end
389
+
390
+ class Comment ::API < Grape ::API
391
+ mount Voting ::API
392
+ end
393
+ ```
394
+
395
+ Assuming that the post and comment endpoints are mounted in ` /posts ` and ` /comments ` ,
396
+ you should now be able to do ` get /posts/votes ` , ` post /posts/votes ` , ` get /comments/votes `
397
+
398
+ ### Configuration
399
+
400
+ You can configure remountable endpoints for small details changing according to where
401
+ they are mounted
402
+
403
+ ``` ruby
404
+ class Voting ::API < Grape ::RemountableAPI
405
+ namespace ' votes' do
406
+ desc " Vote for your #{ configuration[:votable ] } "
407
+ get do
408
+ # Your logic
409
+ end
410
+ end
411
+ end
412
+
413
+ class Post ::API < Grape ::API
414
+ mount Voting ::API , with: {votable: ' posts' }
415
+ end
416
+
417
+ class Comment ::API < Grape ::API
418
+ mount Voting ::API , with: {votable: ' comments' }
419
+ end
420
+ ```
421
+
369
422
## Versioning
370
423
371
424
There are four strategies in which clients can reach your API's endpoints: ` :path ` ,
You can’t perform that action at this time.
0 commit comments