Basic Usage
How to Use the REST API
The Restsocket Server enables easy interaction with your database via a RESTful API. After configuring the connection string and starting the server, it connects to your database and provides endpoints for fetching, creating, updating, and deleting data.
Basic Usage
In Restsocket, all calls use POST requests. The distinction between the user and the server is made through the Bearer Token. The given Bearer Token must be sent in the Authorization header.
fetch('https://r-sock.com/api/fetch/users', {
method: 'POST',
headers: {
'Authorization': 'Bearer your_token',
'Content-Type': 'application/json'
},
body: JSON.stringify({ id: 3 })
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));Replace Bearer your_token with your actual Bearer token.
Example Data
The examples below assume that there is a 'users' table and data as follows.
Table : users
3
Tom
27
100
Fetch Operation
Use the POST call as follows.
End-point
Post Data
{ column1 : value1, ... }
Example
Result
Create Operation
Use the POST call as follows.
End-point
Post Data
{ column1 : value1, column2 : value2, ... }
Example
Result
Update Operation
Use the POST call as follows.
End-point
Post Data
{ "where" : { column1 : value1, ... },
"data" : { column2 : value2, ... } }
Example
Result
Delete Operation
Use the POST call as follows.
End-point
Post Data
{ column1 : value1, ... }
Example
Result
Last updated