0 directories, 11 files

tinai

Home / testing / ai / tinai
class Api {

	#endpoint = 'api.php'

	constructor() {
	}

	format_data(data = '', context = [], debug = false){
		return {
			"context":context,
			"debug":debug,
			"query":data
		};
	}

	async post(data, on_success, on_failure){
		try {
			const response = await fetch(this.#endpoint, {
				method: 'POST',
				headers: {
					'Content-Type': 'application/json'
				},
				body: JSON.stringify(data)
			});
			const response_object = await response.json();
			console.log('Response:', response_object);
			on_success(response_object);
		} catch (error) {
			console.error('Error:', error);
			on_failure(error);
		}
	}


}

export default Api;
🌐
api.js ×
Type: Web, text/plain
646 Bytes
Last Modified 2026-03-07 17:39:56
⬇ Download File