Skip to content

Build URL for remote resource #348

Description

@mrloop

I want to build a URL not trigger an ajax request for a non typical RESTful API. To extend the fruits example in the README I have a API endpoint

GET /fruits/123/print

Example Rails API route:
config/routes.rb

Rails.application.routes.draw do
  resources :fruits do
    member do
      get 'print' to: 'fruits#print'
    end
  end
end

app/models/fruit.js

import DS from 'ember-data';
import { memberUrl } from 'ember-api-actions';

const { attr } = DS;

export default DS.Model.extend({
  uuid: attr('string'),
  // /fruits/123UID/print
  print: memberUrl({ 
    path: 'print',
    id: 'uuid', 
  }),
});

This print URL is then passed to a print service which handles getting the document to print from the URL and printing it (in my case via https://qz.io/)

myPrinterService.printDoc({ url: myRecord.print })

In the above example the record id in the URL is replaced with the record UUID as the endpoint is unauthenticated though should be hard to guess. Would you accept a PR for memberUrl @mike-north ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions