DEV Community

Cover image for What If You Could Write AJAX Without JavaScript? Meet fetchtl.
Jahongir Sobirov
Jahongir Sobirov

Posted on

What If You Could Write AJAX Without JavaScript? Meet fetchtl.

Ever wished you could make an API request without writing a single line of JavaScript?

Yeah… me too 😅
So I built fetchtl — a tiny library that lets you do things like:

<div $get="/api/user"></div>
Enter fullscreen mode Exit fullscreen mode

or even:

<form $post="/api/register" $send-on="submit">
  <input name="email" />
  <button type="submit">Register</button>
</form>
Enter fullscreen mode Exit fullscreen mode

That’s it. No JS. No frameworks. No fetch(). Just HTML.

🌟 Why I Created fetchtl

As a web developer, I got tired of doing this 100 times:

fetch("/api/user")
  .then(res => res.json())
  .then(data => {
    document.querySelector("#user").innerHTML = data.name;
  });
Enter fullscreen mode Exit fullscreen mode

Too much boilerplate. Too much repetition.
I wanted something like:
“Just write HTML and let the page fetch automatically.”
So I created fetchtl — a tool that gives HTML magical new attributes:

  • $get → Load data from an API
  • $post → Submit a form via AJAX

🚀 What Exactly Is fetchtl?

fetchtl is a JavaScript helper that watches your HTML for special attributes and automatically performs API calls.

No build tools. No configs. No React. No Vue.
Just include it and start using it:

<script src="https://cdn.jsdelivr.net/gh/jahongir2007/fetchtl/fetchtl.js"></script>
Enter fullscreen mode Exit fullscreen mode

Now HTML becomes smart.

🤯 Example: Load API Data with Just One Attribute

Before fetchtl (traditional way)

<div id="user"></div>

<script>
fetch("/api/user")
  .then(res => res.json())
  .then(data => {
    document.getElementById("user").innerHTML = data.name;
  });
</script>
Enter fullscreen mode Exit fullscreen mode

With fetchtl 🚀

<div $get="/api/user">
  Loading...
</div>
Enter fullscreen mode Exit fullscreen mode

fetchtl does everything automatically:

  • fetches the URL
  • replaces the inside HTML
  • handles JSON
  • updates instantly

📝 Example: AJAX Form Without JavaScript

Before

document.querySelector("form").addEventListener("submit", e => {
  e.preventDefault();
  const formData = new FormData(e.target);

  fetch("/api/register", {
    method: "POST",
    body: formData
  });
});
Enter fullscreen mode Exit fullscreen mode

With fetchtl 💛

<form $post="/api/register" $send-on="submit" $reload="false">
  <input name="email" placeholder="Your email" />
  <button type="submit">Register</button>
</form>
Enter fullscreen mode Exit fullscreen mode
  • The form submits via AJAX automatically.
  • The page doesn’t reload.
  • You didn’t write any JavaScript.

Built-in template engine (e.g. $name → replaced by JSON value)

So you can get directly and json object value by calling its name

<div $get='/user'>
User name: $name
</div>
Enter fullscreen mode Exit fullscreen mode

🔄 Auto-refresh sections

With $poll you can refresh any section of your web page

<div $get='/api/status' $poll='2000'>
User status: $status
</div>
Enter fullscreen mode Exit fullscreen mode
  • $poll means that every 2000 ms or 2 seconds fetchtl sends request to server Useful for:
    • live dashboards
    • instant search
    • real-time forms

Github page: https://github.com/Jahongir2007/fetchtl

Top comments (2)

Collapse
 
ravavyr profile image
Ravavyr

lol, this sounds neat and all, but in a real project...
You're gonna be expanding your lib to process POSTs and callback functions and you're just gonna end up with a lot more boilerplate than a regular fetch just to accomplish the exact same thing.

Yours is still JavaScript... you're just hiding it inside a lib file and it's only a partial solution to the full problem.

If you're just using this for your pet project, enjoy, we all do this stuff eventually.
But please don't use it on client projects that someone else will have to take over/change/fix/debug/whatever in the future.

In the end, someone else is gonna be looking at code you produce in like 2 or 3 years and go "WTF is this?" unless your little library becomes something popular.

Collapse
 
jahongir2007 profile image
Jahongir Sobirov

Hey! Thanks a lot for the thoughtful feedback — really appreciate it. 🙏

You're absolutely right about one thing:
fetchtl is not trying to replace full frontend frameworks or large-scale JS architectures.

It’s intentionally small and intentionally limited.

🧠 The purpose of fetchtl is:

To remove simple, repetitive fetch() boilerplate

To make HTML more expressive for beginners

To help people building small projects, cPanel apps, prototypes, landing pages, admin dashboards, etc.

To serve as an experiment in HTML-driven API calls — similar to Alpine.js or HTMX but way lighter

🪶 And yes — internally it's still JavaScript

I’m not hiding that.
fetchtl simply maps HTML attributes → JS behaviors, the same way HTMX uses hx-get, Vue uses v-model, React uses JSX attributes.

This is the natural pattern of modern UI libraries.