Don not put main.html with css and js in same folder as API. It should look something like this:
-
htdocs/
- main.html
- styles.css
- scripts.js
php-rest-api/
- index.php
src/
I know, it does not supprt messages/errors from api
Source code to accompany this video: https://youtu.be/X51KOJKrofU
- Basic REST API routing and URLs
- List, show, create, update and delete database records using a RESTful API
- Best-practice code organisation
- Controllers and table gateways
- Relevant HTTP status codes
- Data validation
- JSON decoding and encoding
Complete API course, including authentication: https://davehollingworth.net/phpapisy