js-php-mysql-crud-api
v2.1.2
Published
This is a minimal JavaScript wrapper for the incredible [PHP CRUD API](https://github.com/mevdschee/php-crud-api) by Maurits van der Schee.
Downloads
7
Readme
JavaScript PHP MySQL CRUD API
This is a minimal JavaScript wrapper for the incredible PHP CRUD API by Maurits van der Schee.
🚨 No more maintenance - you can use https://github.com/thipages/js-crud-api
Installation
Create a new app project:
npm create vite
Add a PHP backend
npx add-php-backend
Install this module:
npm install js-php-mysql-crud-api
Usage
import useAPI from 'js-php-mysql-crud-api'
const api = useAPI()
(async () => {
// Add some records to the table
await api.create('tasks', { title: 'First' })
await api.create('tasks', { title: 'Second' })
await api.create('tasks', { title: 'Third' })
// Retrieve a list of all records
const records = await api.list('tasks')
// Log them to the console
console.log(records)
})()
Methods
Change the API endpoint if required (default /api.php
):
setEndpoint(endpoint)
According to the CRUD + List operations:
create(table, item)
read(table, key)
update(table, key, item)
delete(table, key)
list(path)
According to the Database Authentication operations:
me()
register(username, password)
login(username, password)
password(username, password, newPassword)
logout()
Request function for Custom Controller:
request(path, options = {})