A REST API (Representational State Transfer Application Programming Interface) is a programming interface based on the REST architecture that allows systems to communicate over a network (such as the internet). It utilizes HTTP methods (e.g., GET, POST, PUT, DELETE) and can transmit data in various formats, such as JSON or XML, to connect clients and servers. REST APIs are stateless and allow the separation of client and server, promoting high flexibility, scalability, and component independence.
K8 Web Kit as a REST API
Requests
Method and urls:
Headers:
Body:
A body is necessary for the methods: POST and PATCH.
Supported methods:
- GET
- POST
- PATCH
- DELETE
Endpoints
The datadefIDs are the endpoints.
Authorization
The Authorization type is Basic Authorization with:
- username
- password
More authorization conditions:
- only active users are supported
- config/_init.php:
- domain_restroles: only user with the defined roles are allowed to send REST requests
- 3 failed login attemps in 1 hour are allowed, the failed attemps with IP are saved in the table k8fail2ban
Response
HTTP-Status: 200,201,400,... Response:
The content of the response depends on request method and API service.
Exmaples for HTTP status:
- 200: OK
- 201: creatd
- 400: bad request
- 403: forbidden
- ... more
Requirements
Folder: restapi
index.php has access to the database and data definitions. It checks:
- credencials
- request method
- endpoints (datadefID)
It sends the response.
.htaccess:
The .htaccess redirects all REST API requests to the file restapi/index.php
config/_init.php
A registered user needs the roles: 2 or 105. You need your own installation of K8 Web Kit and establish your own REST API.
The HTTP playground: postman.com
postman.com offers a comfortable playground for checking out API services. You can create your own workspaces. Enter your request, test and save them.
Visit:
Request with K8 Web Kit
PHP, request with curl:
Request
- method
- url
- header
- body
Response
- http_status
- response
- header
- body
The credencials are in the header. So the request is done in the backend to hide the credentials.
PHP, request with the connector object:
Connector
The connector is defined in the config/_init.php. It contains url, credentials and header. The REQUEST contains the parameter:
- method
- url
- body
The variable result returns the request:
- http_status
- response
- error
Testing with K8 Web Kit (under construction):
Request with JavaScript
JavaScript example for REST request
Curl Method in php
The curl method needs to be executed in php, url:
- masterdata/ProcessMethod.php?process_action=curl
The curl parameters are set in the variable payload:
- connector
- method
- url
- body
The response is in the object resp. Properties are:
- bok
- error
- response
- http_status