Metadata-Version: 2.4
Name: robotframework-requests-log
Version: 1.2.0
Summary: Robot Framework library for beautiful API request/response HTML log cards
License: MIT
Project-URL: Homepage, https://github.com/heynirinx/RequestsLog
Project-URL: Repository, https://github.com/heynirinx/RequestsLog
Keywords: robotframework,testing,api,http,logging,requests
Classifier: Programming Language :: Python :: 3
Classifier: Framework :: Robot Framework
Classifier: Framework :: Robot Framework :: Library
Classifier: Topic :: Software Development :: Testing
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: robotframework>=5.0
Requires-Dist: requests>=2.20
Dynamic: license-file

# RequestsLog

[ภาษาไทย](#ภาษาไทย) | [English](#english)

---

## ภาษาไทย

Robot Framework library สำหรับยิง HTTP request (ครอบ `requests` อีกที) พร้อมสร้าง log
เป็นการ์ด HTML ที่อ่านง่าย แสดง request/response headers, body (JSON syntax highlight),
คำสั่ง curl ที่สร้างให้อัตโนมัติ, สถานะ, และเวลาที่ใช้ในการเรียกแต่ละ request

รองรับ keyword: `Send Request GET`, `Send Request POST`, `Send Request PUT`,
`Send Request PATCH`, `Send Request DELETE`, `Send Request HEAD`, `Send Request OPTIONS`

> **หมายเหตุ (v1.2.0):** ชื่อ keyword เปลี่ยนจาก `GET`/`POST`/... เป็น
> `Send Request GET`/`Send Request POST`/... เพื่อไม่ให้ชนกับ
> [RequestsLibrary](https://github.com/MarketSquare/robotframework-requests)
> ที่ใช้ชื่อ `GET`/`POST` เปล่า ๆ ทำให้ import สองไลบรารีพร้อมกันได้
> ถ้าอัปเกรดจาก 1.1.0 ต้องเติม `Send Request ` นำหน้าทุก keyword ในเทสเดิม

### สิ่งที่ต้องมีก่อนติดตั้ง

- Python 3.8 ขึ้นไป
- pip

เมื่อติดตั้งผ่าน pip แพ็กเกจ `robotframework` และ `requests` จะถูกติดตั้งให้อัตโนมัติ
(เป็น dependency ของ RequestsLog)

### การติดตั้ง

แพ็กเกจถูก publish ขึ้น PyPI แล้วในชื่อ `robotframework-requests-log`
ติดตั้งได้โดยตรงด้วยคำสั่ง:

```bash
pip install robotframework-requests-log
```

ตรวจสอบว่าติดตั้งสำเร็จ:

```bash
python -m pip show robotframework-requests-log
```

### การใช้งาน

Import library เข้าไฟล์ `.robot`:

```robotframework
*** Settings ***
Library    RequestsLog
```

ตัวอย่างการเรียกใช้งาน keyword:

```robotframework
*** Settings ***
Library    RequestsLog

*** Variables ***
${BASE_URL}    https://jsonplaceholder.typicode.com

*** Test Cases ***
GET Request พื้นฐาน
    ${response}=    Send Request GET    ${BASE_URL}/posts/1    expected_status=200
    Should Not Be Empty    ${response.json()}[title]

POST Request พร้อม JSON Body
    ${body}=    Create Dictionary    title=hello    body=world    userId=1
    ${response}=    Send Request POST    ${BASE_URL}/posts    json=${body}    expected_status=201
    Should Be Equal As Strings    ${response.json()}[title]    hello
```

ดูตัวอย่างเพิ่มเติมได้ที่ [`example.robot`](example.robot) ซึ่งครอบคลุมทุก keyword
(GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS) รวมถึงการใช้ `params`, `headers`,
`timeout`, `expected_status` และ `msg`

#### พารามิเตอร์หลักของแต่ละ keyword

- `url` — URL ปลายทาง (จำเป็น)
- `params` — query string เป็น dictionary
- `data` / `json` — body ของ request (สำหรับ POST/PUT/PATCH)
- `headers` — headers เป็น dictionary
- `timeout` — เวลา timeout เป็นวินาที (default 30)
- `verify` — ตรวจสอบ SSL certificate หรือไม่ (default True)
- `expected_status` — status code ที่คาดหวัง หากไม่ตรงจะ raise `AssertionError`
  (ใส่ `any` หรือ `anything` เพื่อยอมรับทุก status code, ถ้าไม่ระบุจะใช้ `raise_for_status()` ของ requests แทน)
- `msg` — ข้อความ error ที่กำหนดเองเมื่อ `expected_status` ไม่ตรง

ทุก keyword คืนค่าเป็น `requests.Response` object ตามปกติ และจะบันทึก log การ์ด HTML
ลงใน log ของ Robot Framework โดยอัตโนมัติทุกครั้งที่เรียก

### ตัวอย่างหน้าตา log

**GET**
![ตัวอย่าง log ของ GET request](images/get-example.png)

**POST**
![ตัวอย่าง log ของ POST request](images/post-example.png)

**PUT**
![ตัวอย่าง log ของ PUT request](images/put-example.png)

**PATCH**
![ตัวอย่าง log ของ PATCH request](images/patch-example.png)

**DELETE**
![ตัวอย่าง log ของ DELETE request](images/delete-example.png)

---

## English

Robot Framework library for making HTTP requests (a wrapper around `requests`) that
automatically generates readable HTML log cards showing request/response headers, body
(with JSON syntax highlighting), an auto-generated curl command, status, and the time
taken for each request.

Supported keywords: `Send Request GET`, `Send Request POST`, `Send Request PUT`,
`Send Request PATCH`, `Send Request DELETE`, `Send Request HEAD`, `Send Request OPTIONS`

> **Note (v1.2.0):** keywords were renamed from `GET`/`POST`/... to
> `Send Request GET`/`Send Request POST`/... so they no longer clash with
> [RequestsLibrary](https://github.com/MarketSquare/robotframework-requests),
> which defines bare `GET`/`POST` keywords — both libraries can now be imported
> into the same suite. Upgrading from 1.1.0 requires prefixing every call with
> `Send Request `.

### Prerequisites

- Python 3.8 or higher
- pip

Installing via pip will automatically install the `robotframework` and `requests`
packages (dependencies of RequestsLog).

### Installation

The package is published on PyPI as `robotframework-requests-log`.
Install it directly with:

```bash
pip install robotframework-requests-log
```

Verify the installation:

```bash
python -m pip show robotframework-requests-log
```

### Usage

Import the library in your `.robot` file:

```robotframework
*** Settings ***
Library    RequestsLog
```

Example keyword usage:

```robotframework
*** Settings ***
Library    RequestsLog

*** Variables ***
${BASE_URL}    https://jsonplaceholder.typicode.com

*** Test Cases ***
Basic GET Request
    ${response}=    Send Request GET    ${BASE_URL}/posts/1    expected_status=200
    Should Not Be Empty    ${response.json()}[title]

POST Request With JSON Body
    ${body}=    Create Dictionary    title=hello    body=world    userId=1
    ${response}=    Send Request POST    ${BASE_URL}/posts    json=${body}    expected_status=201
    Should Be Equal As Strings    ${response.json()}[title]    hello
```

See more examples in [`example.robot`](example.robot), which covers every keyword
(GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS) including the use of `params`, `headers`,
`timeout`, `expected_status`, and `msg`.

#### Main parameters for each keyword

- `url` — target URL (required)
- `params` — query string as a dictionary
- `data` / `json` — request body (for POST/PUT/PATCH)
- `headers` — headers as a dictionary
- `timeout` — timeout in seconds (default 30)
- `verify` — whether to verify the SSL certificate (default True)
- `expected_status` — the expected status code; raises `AssertionError` if it doesn't
  match (pass `any` or `anything` to accept any status code; if not specified,
  `requests`' `raise_for_status()` is used instead)
- `msg` — custom error message when `expected_status` doesn't match

Every keyword returns a normal `requests.Response` object, and automatically logs an
HTML card to the Robot Framework log each time it's called.

### Log preview

**GET**
![GET request log example](images/get-example.png)

**POST**
![POST request log example](images/post-example.png)

**PUT**
![PUT request log example](images/put-example.png)

**PATCH**
![PATCH request log example](images/patch-example.png)

**DELETE**
![DELETE request log example](images/delete-example.png)
