HTAPI Lite v.1.0

The coolest lightweight JavaScript library
for HTML to API magicπŸ§™β€ ~2kb

πŸŽ‰ Embrace the power of HTAPI! ⚑

🎈 HTAPI Lite is a lightweight JavaScript library that magically transforms your HTML data into a GET friendly API! Isn't that awesome? 🎈

🌟 Data attributes 🌟

  • htapi-api-name 😎: The big name for your key-value pairs
  • htapi-return βœ…: Set to "json" to tell the script you're ready to roll
  • htapi-data 🀳: Set to "self" so the script knows it's all about the current element
  • htapi-data-element πŸ“: Set to "list" when you have a list of key-value pairs
  • htapi-key πŸ”‘: Your super cool key for the key-value pair
  • htapi-value 🎁: The value of your key-value pair

πŸ“š Usage πŸ“š

  1. πŸ“₯ Include the HTAPI <script src="https://cdn.htapi.io/lite/htapi-v1-lite.js"></script> anywhere in your HTML
  2. 🏷️ Add the required data attributes to your HTML elements to create the HTAPI endpoint data structures

🎯 Example 🎯

Let's say we have an unordered list with user data, and we want to expose this data as JSON using HTAPI. Check out this example: πŸ§™β€β™‚οΈ

<ul htapi-api-name="users" htapi-return="true" htapi-data="self" htapi-data-element="list">
  <li htapi-key="name">Name<span htapi-value="value">Value</span></li>
</ul>

πŸ” Let's break it down: πŸ”

  • htapi-api-name="users" πŸ“›: Specifies the object name for the key-value pairs
  • htapi-return="true" ⏭️, htapi-data="self" 🧍, and htapi-data-element="list" πŸ“‹: These attributes tell the script to process this element and look for key-value pairs
  • htapi-key="name" πŸ—οΈ: Specifies the key for the key-value pair
  • htapi-value="value πŸŽ€: Specifies the value for the key-value pair
  • htapi-match="key|value" πŸ”Ž htapi-match: Fetches specific object based on key-value pair, separated by a pipe (|)

πŸ”— URL Parameters Examples πŸ”—

  • https://cdn.htapi.io/endpoints/demo.html?htapi-return=json - πŸš€ Fetch all data
  • https://cdn.htapi.io/endpoints/demo.html?htapi-return=json&htapi-api-name=users - πŸ§‘β€πŸ’» Get specific data: users
  • https://cdn.htapi.io/endpoints/demo.html?htapi-return=json&htapi-api-name=orders - πŸ› Get specific data: orders
  • https://cdn.htapi.io/endpoints/demo.html?htapi-return=json&htapi-api-name=products - πŸ“¦ Get specific data: products

Click the button above to test the HTAPI Endpoint and see the magic happen! 🌟 The response will appear if we're connected. Enjoy! πŸ˜ƒ

🌳

Nested APIs

HTAPI also supports nested APIs, so you can create more complex data structures in your HTML🌳 Here's an example:

<div htapi-api-name="orders">
  <div htapi-key="order_id" htapi-value="123">
    <div htapi-key="product" htapi-value="Shoes">
      <div htapi-obj-key="Brand" htapi-obj-value="Nike"></div>
      <div htapi-obj-key="Size" htapi-obj-value="10"></div>
      <div htapi-obj-key="Color" htapi-obj-value="Black"></div>
    </div>
    <div htapi-key="quantity" htapi-value="2"></div>
    <div htapi-key="price" htapi-value="49.99"></div>
  </div>
</div>