8. Faking Data

Dave Wexler edited this page Jan 11, 2017 · 4 revisions

Make Up Data

The following workflow describes how to create a full stack of XapiX resources that are freely combinable with every other XapiX resource. All you need is a google sheet. This is especially useful:

  • To Mock Resource Classes that you wish would exist backed with a real team-editable data source
  • When you miss entries in an existing data source, create your own one and map them into the same Resource Class
  1. Creating your external Data Source with "Google Sheets"

  2. Sign in to your Google Account and create a "Sheet" in the Sheets app

  3. On very first row enter column headings. Use letters, numbers and underscores only (no whitespaces)!

  4. Use one column as an identifier (ID) column identifying each individual row. In the simplest form they'd just equal the row number of your sheet. Fill the rest of your columns as you like according to the headings row.

  5. On the Sheets menu, select "File" -> "Publish to the Web". On the now open menu unfold "Published content & settings", leave the checkbox "Automatically republish when changes are made" checked and hit the "Start publishing" button. You'll get a confirmation dialog next. On the "Link" tab select Comma-separated-values (.csv) and copy & paste that link somewhere you find it back. If you want to test: Pasting that link in your browser URL field should download that file to your computer.

  6. If you later decide to add more rows or change entries, these changes will propagate all the way to your XapiX endpoint.

  7. Getting your data into XapiX

  8. On your existing XapiX Project Add a Web Interface (Sidebar -> Web Interfaces -> Add)

  9. Enter a "Name", select "Type" -> "csv" and paste the Sheets URL you got at 1.4. into "URL" field. Hit "Create Web Interface" button. You should see a confirmation screen displaying one of your data sets.

  10. Specifying the Output Format in XapiX

  11. On your existing XapiX Project Add a Resource Class (Sidebar -> Resources Classes -> Add)

  12. Enter names. The "resource collection name" shall be the plural form of the "individual resource name". Hit the "Create Resource Class" button.

  13. Visit it's "Dashboard" and within the "Resource Class Attributes and Relationships" section add all attributes according to heading columns in 1.2. Hit the "Save" Button you'll find next to the section's heading.

  14. Select the identifier (ID) column from 1.3. as "Individual resource identifier" and hit "Save" again.

  15. If you'd like your resource's data sets to be filterable by an attribute, click on the "Edit" button next to it. In the following menu you can set it to be filterable. There are further features documented here.

  16. Mapping Data from source Web Interface to Resource Class

  17. On your existing XapiX Project Add a Mapping (Sidebar -> Mappings -> Add)

  18. Select a name, the Web Interfaces and Resource Classes you just created and select "Purpose" -> "Live". Live-Mapping means XapiX triggers a query to Google Sheets source file on each API call, which is slower but this way changes on your Google Sheet instantly propagate through to XapiX API output. Further Read.

  19. Do a 1:1 Mapping by dragging a Web Interface Attribute from the left to the according Resource Class Attribute on the right. Hit the "Create" button. Repeat until all are mapped.

Congrats, you're done!

  • Check Resource Class by visiting it's Dashboard. The "Result Based on Mapped Web Interface Data Samples" section should indicate your Mapping succeeded.
  • On your Sidebar -> Project Dashboard toggle the "Test Resource Classes" section and click on the link belonging to your Resource Class. The Web CLI should open and display the data sets of your Excel sheet in raw jsonapi.org output format.

Generating Test Data

  1. go to new Resource Class via sidebar navigation
  2. create Resource Class
  3. go to Resource Class dashboard
  4. add some Resource Class Attributes
  5. pick Resource Class's individual resource identifier
  6. set Resource Class Attribute to be filterable if desired
  7. check Resource Class dashboard
  8. go to new Resource Class Fake
  9. create Resource Class Fake
  10. check Resource Class Fake dashboard
  11. publish fake data to S3
  12. generate Web Interface
  13. generate Mapping
  14. edit Mapping
  15. set Mapping purpose to static