
The coolest lightweight JavaScript library
for HTML to API magicπ§β ~2kb
π HTAPI Lite is a lightweight JavaScript library that magically transforms your HTML data into a GET friendly API! Isn't that awesome? π
htapi-api-name π: The big name for your key-value pairshtapi-return β
: Set to "json" to tell the script you're ready to rollhtapi-data π€³: Set to "self" so the script knows it's all about the current elementhtapi-data-element π: Set to "list" when you have a list of key-value pairshtapi-key π: Your super cool key for the key-value pairhtapi-value π: The value of your key-value pair<script src="https://cdn.htapi.io/lite/htapi-v1-lite.js"></script> anywhere in your HTMLLet'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 pairshtapi-return="true" βοΈ, htapi-data="self" π§, and htapi-data-element="list" π: These attributes tell the script to process this element and look for key-value pairshtapi-key="name" ποΈ: Specifies the key for the key-value pairhtapi-value="value π: Specifies the value for the key-value pairhtapi-match="key|value" π htapi-match: Fetches specific object based on key-value pair, separated by a pipe (|)https://cdn.htapi.io/endpoints/demo.html?htapi-return=json - π Fetch all datahttps://cdn.htapi.io/endpoints/demo.html?htapi-return=json&htapi-api-name=users - π§βπ» Get specific data: usershttps://cdn.htapi.io/endpoints/demo.html?htapi-return=json&htapi-api-name=orders - π Get specific data: ordershttps://cdn.htapi.io/endpoints/demo.html?htapi-return=json&htapi-api-name=products - π¦ Get specific data: productsClick the button above to test the HTAPI Endpoint and see the magic happen! π The response will appear if we're connected. Enjoy! π
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>