Loading repository data…
Loading repository data…
JunusErgin / repository
PHP-Based Skript to store a JSON-Array on a server
There is no security layer implemented. This tool should not be used for production systems and is no replacement for a real middleware system with based on a framework and with a real database.
smallest_backend_ever file to your FTP servermini_backend.js to your project<script src="./mini_backend.js"></script>setURL('http://developerakademie.com/smallest_backend_ever');
(e.g. to the init() method)localStorage APIIf you want to see a full working example, open the file example.html.
Imagine we're having an array of users:
let users = [];
Add a user with this function:
function addUser() {
users.push('John);
backend.setItem('users', JSON.stringify(users));
}
If you want to wait for the request you can add the await keyword as well:
Add a user with this function:
async function addUser() {
users.push('John);
await backend.setItem('users', JSON.stringify(users));
}
Fill your empty array with users from the Server
async function init() {
await downloadFromServer();
users = JSON.parse(backend.getItem('users')) || [];
}
Delete all users from your array:
function deleteUser(name) {
await backend.deleteItem('users');
}
This projekt was created to explain the usage of a Library and basic HTTP functions for students of Developer Akademie.