https://github.com/simplyyan/lymplerequest
A small library for making easy requests in JS
https://github.com/simplyyan/lymplerequest
backend get javascript js post requests server-side vanilla-javascript
Last synced: 10 months ago
JSON representation
A small library for making easy requests in JS
- Host: GitHub
- URL: https://github.com/simplyyan/lymplerequest
- Owner: simplyYan
- License: bsd-3-clause
- Created: 2024-04-03T15:17:22.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-03T15:52:57.000Z (almost 2 years ago)
- Last Synced: 2025-02-07T06:22:46.266Z (11 months ago)
- Topics: backend, get, javascript, js, post, requests, server-side, vanilla-javascript
- Language: JavaScript
- Homepage:
- Size: 16.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
**Lymple**
Welcome to the lympleRequest (lymple) - a lightweight JavaScript library for making GET and POST requests easily and efficiently. Communicate with your favorite back-end language, any language.
### Introduction
Lymple is an easy-to-use tool for interacting with APIs and web servers directly from your browser. With it, you can asynchronously send and receive data, enabling the building of dynamic and interactive web applications.
### Installation
You can use Lymple by either including the code directly in your JavaScript scripts or by saving it in a separate file and including it in your HTML.
```html
```
### Basic Usage
#### GET Requests
To make a GET request, you need to provide the URL of the resource you want to access and a callback function to handle the response.
```javascript
lymple.get('https://api.example.com/data', function(response) {
console.log(response); // Here you can process the response
});
```
#### POST Requests
To make a POST request, in addition to the URL, you need to provide the data to be sent as a JavaScript object and a callback function to handle the response.
```javascript
var data = { name: 'John', age: 25, city: 'New York' };
lymple.post('https://api.example.com/submit', data, function(response) {
console.log(response); // Here you can process the response
});
```
### More Details
#### Error Handling
Lymple automatically handles network errors, such as connection failures or unexpected server responses. You can add error handlers to your callback function to deal with these situations.
```javascript
lymple.get('https://api.example.com/data', function(response) {
console.log(response);
}, function(error) {
console.error('An error occurred:', error);
});
```
#### Sending Custom Headers
You can send custom headers with your requests, such as authorization or content headers. Simply add an object containing the desired headers as the last parameter.
```javascript
var headers = { 'Authorization': 'Bearer token123' };
lymple.get('https://api.example.com/data', function(response) {
console.log(response);
}, null, headers);
```
### Conclusion
Lymple is a powerful and versatile tool for handling HTTP communications in the browser. With its simple and easy-to-use design, you can easily integrate it into your projects to interact with APIs and web servers efficiently and reliably.
If you have any questions or suggestions, feel free to contact us!
### Examples
- **GET Request**: Fetching weather data from a weather API.
```javascript
lymple.get('https://api.weatherapi.com/forecast.json?key=YOUR_API_KEY&q=London', function(response) {
console.log(response);
});
```
- **POST Request**: Sending form data to the server.
```javascript
var data = { name: 'Maria', age: 30, city: 'Rio de Janeiro' };
lymple.post('https://api.example.com/submit', data, function(response) {
console.log(response);
});
```
- **GENERAL EXAMPLE**:
```html
Document
Send
function send() {
var nome = document.getElementById("nome").value;
var data = { name: nome }
lymple.post('index.php', data, function(response) {
console.log(data)
console.log(response);
}, { 'Content-Type': 'application/json' });
}
```
```php
```
With these examples, you can start using Lymple in your projects and leverage its features to enhance communication between your web application and servers.