Skip to content

Commit 8f571e3

Browse files
Merge pull request #2 from Modularity-Bulgaria/feat/update-readme
Update README
2 parents 970377f + c2c0179 commit 8f571e3

1 file changed

Lines changed: 62 additions & 2 deletions

File tree

README.md

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,64 @@
11
# http_build_query
2-
Javascript port of PHP http_build_query
32

4-
WIP
3+
[![codecov](https://codecov.io/gh/Modularity-Bulgaria/http_build_query/branch/main/graph/badge.svg?token=HS160E15RY)](https://codecov.io/gh/Modularity-Bulgaria/http_build_query)
4+
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/Modularity-Bulgaria/http_build_query/CI%20Build)
5+
6+
## Introduction
7+
8+
Have you ever found yourself needing to connect to a legacy PHP API that requires the usage of `http_build_query` with **RFC1738**?
9+
10+
This library will enable you to do so with ease :beer:
11+
12+
## Requirements
13+
- NodeJS 12.x
14+
15+
## Installation
16+
17+
Install using either `npm` or `yarn`
18+
```sh
19+
npm i @modularitybg/http_build_query
20+
//or
21+
yarn add @modularitybg/http_build_query
22+
```
23+
24+
## How to use
25+
26+
```js
27+
const httpBuildQuery = require('@modularitybg/http_build_query');
28+
29+
const rfcFormattedQuery = httpBuildQuery({
30+
amount: { amount: 2900 },
31+
stringValueWithWhiteSpace: "String Value",
32+
city: "Unlandstraße",
33+
arrayValues: [1, "string"],
34+
})
35+
``
36+
//Result
37+
"amount=%7B%22amount%22%3A2900%7D&stringValueWithWhiteSpace=String+Value&city=Unlandstra\\u00dfe&arrayValues=%5B1%2C%22string%22%5D"
38+
```
39+
_Notice that special characters are transformed using UTF-8 mapping, similar to how is handled in PHP_
40+
41+
42+
## Why not simply use _URLSearchParams_?
43+
44+
Let's compare the difference:
45+
```js
46+
nativeQueryResult = new URLSearchParams({
47+
amount:{
48+
amount: 2900
49+
},
50+
stringValueWithWhiteSpace: "String Value",
51+
city: "Unlandstraße",
52+
arrayValues: [1, "string"]
53+
}).toString()
54+
55+
//Result
56+
'amount=%5Bobject+Object%5D&stringValueWithWhiteSpace=String+Value&city=Unlandstra%C3%9Fe&arrayValues=1%2Cstring'
57+
```
58+
59+
This type of encoding may not be compatible with the API you are trying to connect.
60+
Notice the **Object**, **arrayValues** definitions and the **special character** in the city name.
61+
62+
## License
63+
64+
MIT

0 commit comments

Comments
 (0)