Back

Labor Regulations API

This api endpoint is provided by MGMAemp.

API Endpoint: https://api.mgmaemp.com/regulabor/???/list

API Key: ???

For ???: Contact 09257313341 (call or viber)

Frontend Example

Get List

document.addEventListener("DOMContentLoaded", async () => {
const apiUrl = "https://api.mgmaemp.com/regulabor/???/list";
const res = await fetch(apiUrl, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ aid: "???" })
});
const data = res ? (await res.json() as { message: [Record<string, string>] }) : { message: [] };
console.log(data.message);
});

Read File

async function getContent() {
    const epb = document.getElementById('ext-post-body') as HTMLDivElement;
    const sp = new URL(window.location.href).searchParams;
    const fid = sp.get("fid"); // post_filename
    const ext = sp.get("ext"); // post_mime
    const url = `https://docs.mgmaemp.com/public/extposts/${fid}/content.${ext}`;
    const res = await fetch(url);
    const rawHtml = res ? await res.text() : "";
    const doc = new DOMParser().parseFromString(rawHtml, "text/html");
    const source = doc.querySelector("#ext-post-body");
    if (source) {
        epb.innerHTML = source.innerHTML;
    }
}

Backend Example

Getting list can also be implemented in server side based on the above example.

For server side rendering of read file, a dom parser may be required. The followings are recommended:

  • jsdom
    jsdom is a pure-JavaScript implementation of many web standards, notably the WHATWG DOM and HTML Standards, for use with Node.js. In general, the goal of the project is to emulate enough of a subset of a web browser to be useful for testing and scraping real-world web applications.
  • node-html-parser
    Fast HTML Parser is a very fast HTML parser. Which will generate a simplified DOM tree, with element query support.
  • html-dom-parser
    HTML to DOM parser that works on both the server (Node.js) and the client (browser):
  • linkedom
    LinkeDOM is a triple-linked list based DOM-like namespace, for DOM-less environments, with the following goals:
  • Any other you prefer