API tin tức công khai
REST API JSON cho phép mobile app / widget / chatbot lấy tin tức đã đăng từ TRANG THÔNG TIN ĐIỆN TỬ HỢP TÁC XÃ NÔNG NGHIỆP HỮU CƠ HỒNG PHÁT.
Read-only (GET)
Không cần token
Throttle 120 req/phút/IP
Cache 3 phút
Endpoints
Click Mở để xem dữ liệu trực tiếp (?pretty=1 cho JSON indent đẹp).
GET
GET
https://htx.demokh.vnptdaklak.vn/api/posts/{slug}
Chi tiết 1 bài theo slug (kèm body, attachments, linked audio/video).
RSS
Query parameters
| Param | Loại | Mặc định | Mô tả |
|---|---|---|---|
| type | string | — | Lọc theo loại: news, resource, video, audio, event… |
| category | slug | — |
Lọc theo slug chuyên mục.
VD:
tin-tuc-htx, san-pham-ocop, ky-thuat-canh-tac, thi-truong-gia-ca, chinh-sach-nn, hoat-dong-cong-dong
|
| tag | slug | — | Lọc theo tag (hashtag). |
| q | string | — | Tìm trong tiêu đề + mô tả ngắn. |
| limit | int (1–50) | 20 | Số bài mỗi trang. |
| page | int | 1 | Phân trang. |
| pretty | bool | 0 | Format JSON cho dễ đọc trên browser. |
Ví dụ response
Gọi GET https://htx.demokh.vnptdaklak.vn/api/posts?type=news&limit=2
{ "data": [ { "id": "01HKZ8…", // ULID public_id "type": "news", "title": "Khai mạc cuộc thi tìm hiểu pháp luật 2026", "slug": "khai-mac-cuoc-thi-tim-hieu-phap-luat-2026", "excerpt": "Ngày 19/05, BTC chính thức khai mạc…", "cover_image": "https://…/storage/posts/abc.jpg", "video_url": null, "is_featured": true, "published_at": "2026-05-19T08:30:00+07:00", "category": { "name": "Tin sự kiện", "slug": "tin-su-kien" }, "author": { "name": "Nguyễn Văn A" }, "tags": [], "link": "https://…/posts/01HKZ8…" } ], "meta": { "total": 128, "per_page": 2, "current_page": 1, "last_page": 64 }, "links": { "self": "…/api/posts?type=news&limit=2", "rss": "…/rss", "docs": "…/api" } }
Cách gọi
cURL
curl -s "https://htx.demokh.vnptdaklak.vn/api/posts?type=news&limit=5"
JavaScript (fetch)
const r = await fetch("https://htx.demokh.vnptdaklak.vn/api/posts?limit=10"); const { data, meta } = await r.json(); console.log(meta.total, data[0].title);
Python (requests)
import requests r = requests.get("https://htx.demokh.vnptdaklak.vn/api/posts", params={"type": "news", "limit": 20}) posts = r.json()["data"] for p in posts: print(p["title"], p["link"])
Lưu ý
- API chỉ đọc — không hỗ trợ POST/PUT/DELETE. Trả lỗi 405 nếu gọi method khác GET.
- Chỉ trả về bài có
status = publishedvàpublished_at ≤ hiện tại. Bài draft/pending/scheduled tự ẩn. - Rate limit 120 req/phút/IP — vượt sẽ nhận HTTP 429.
- Trường
bodychỉ có ở endpoint chi tiết bài, không có trong list (giảm dung lượng). - Khi đổi locale (vi/en) qua session, API trả về bài tương ứng — bài chưa dịch sẽ tự ẩn ở locale=en.