Overview
Context
Changes
Added elisp-http-make-content.el version [58449c42a6].
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
;;(load "~/glibc/dark_c/emacs-symfony-cli/http-content.el")
;;;(global-set-key (kbd "M-m") #'(lambda () (interactive) (elisp-http-content)))
(setq http-token "")
(defun elisp-http-get-header ()
(if-let* ((auth-header (unless (or (null http-token)
(string= http-token ""))
(list (cons "Authorization" (concat "Bearer " http-token)))))
(headers (append
'(("Host" . "localhost:8080")
("Accept" . "*/*")
("Content-Type" . "application/json"))
auth-header)))
headers
))
(setq my-headers
(or (elisp-http-get-header)
'(("Host" . "localhost:8080")
("Accept" . "*/*")
("Content-Type" . "application/json"))))
(defun elisp-http-register-line ()
(let* ((_path (elisp-http-prompt-api))
(path (format "POST /%s HTTP/1.1" _path)))
path))
(defun elisp-http-get-line ()
(let* ((_path (elisp-http-prompt-api))
(path (format "GET /%s HTTP/1.1" _path)))
path))
;;;(elisp-http-register-line)
(defun elisp-http-make-content (method)
(let ((request-line (elisp-http-set-request-line)))
(concat
request-line "\n"
(mapconcat (lambda (x)
(format "%s: %s" (car x) (cdr x)))
my-headers
"\n"))))
;;;(elisp-http-make-content)
(defun elisp-http-register-content ()
"Generate HTTP request content for registration with JSON payload."
(let* ((email (elisp-http-prompt-email))
(password (elisp-http-prompt-password))
(request-line (elisp-http-register-line))
(json-body (json-encode `(("email" . ,email) ("password" . ,password))))
(headers (append my-headers
(list (cons "Content-Length"
(number-to-string (string-bytes json-body))))))
(header-block
(mapconcat (lambda (x) (format "%s: %s" (car x) (cdr x)))
headers
"\n")))
(concat request-line "\n"
header-block "\n\n"
json-body)))
;; Пример использования:
;;;(elisp-http-register-content)
|
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | |
Added elisp-http-prompt.el version [7f908702cf].
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
(defun elisp-http-prompt-api ()
(let* ((prompt-api (propertize "апи: " 'face '(:foreground "cyan" :weight bold))))
(read-from-minibuffer prompt-api)))
(defun elisp-http-prompt-email ()
(let* ((prompt-register (propertize "email: " 'face '(:foreground "cyan" :weight bold))))
(read-from-minibuffer prompt-register)))
(defun elisp-http-prompt-password ()
(let* ((prompt-register (propertize "password: " 'face '(:foreground "red" :weight bold))))
(read-from-minibuffer prompt-register)))
|
| | | | | | | | | | | | |
Added elisp-http-style.el version [1f67a1e622].