项目作者: morbidick

项目描述 :
Components to communicate with a jsonapi
高级语言: HTML
项目地址: git://github.com/morbidick/jsonapi-helpers.git
创建时间: 2017-09-05T14:10:54Z
项目社区:https://github.com/morbidick/jsonapi-helpers

开源协议:

下载


Polymer 2 components to communicate with a jsonapi

Published on webcomponents.org
Build Status

Components to communicate with an api, according to the jsonapi spec.

Components

\

Interact with a jsonapi resource endpoint. Items can be fetched, created, updated and deleted.

  1. <jsonapi-resource
  2. id="getExample"
  3. api-url="http://example.net"
  4. resource="books"
  5. response="{{ my_response }}"
  6. auto-get
  7. ></jsonapi-resource>
  8. <jsonapi-resource
  9. id="getOneExample"
  10. api-url="http://example.net"
  11. resource="books"
  12. resourceId="1"
  13. response="{{ my_response }}"
  14. auto-get
  15. ></jsonapi-resource>
  16. <jsonapi-resource
  17. id="saveExample"
  18. api-url="http://example.net"
  19. resource="books"
  20. ></jsonapi-resource>
  21. <script>
  22. let resource = this.$.saveExample;
  23. resource.data = { title: 'awesome book', author: 'morbidick' };
  24. resource.save();
  25. </script>

\

Set api settings once globally. For now they can’t be overwritten on the jsonapi-resource element.

  1. <jsonapi-settings
  2. api-url="http://example.net"
  3. ></jsonapi-settings>
  4. <jsonapi-resource
  5. resource="books"
  6. response="{{ my_response }}"
  7. auto-get
  8. ></jsonapi-resource>

\

“Singleton Element” to display a toast with the error details if any <jsonapi-resource> on the site encounters an error.

  1. <jsonapi-error-toast></jsonapi-error-toast>
  2. <jsonapi-resource
  3. resource="undefined_endpoint"
  4. auto-get
  5. ></jsonapi-resource>

Development

  1. # Get dependencies
  2. $ npm install
  3. # Demo site
  4. $ npm start
  5. # Run tests
  6. $ npm test