20 lines
775 B
Python
20 lines
775 B
Python
import urllib.request, json
|
|||
|
|
|
||
|
|
# Test write-go: create a post endpoint
|
||
|
|
req = urllib.request.Request('http://localhost:8016/api/posts',
|
||
|
|
data=json.dumps({"frontMatter":{"title":"Test Article","slug":"test-article"},"content":"Hello world"}).encode(),
|
||
|
|
headers={"Content-Type":"application/json"},
|
||
|
|
method='POST')
|
||
|
|
try:
|
||
|
|
r = urllib.request.urlopen(req, timeout=5)
|
||
|
|
print('CREATE POST:', r.status, r.read().decode()[:200])
|
||
|
|
except Exception as e:
|
||
|
|
print('CREATE POST ERROR:', e)
|
||
|
|
|
||
|
|
# Cleanup
|
||
|
|
req2 = urllib.request.Request('http://localhost:8016/api/posts/test-article', method='DELETE')
|
||
|
|
try:
|
||
|
|
r2 = urllib.request.urlopen(req2, timeout=5)
|
||
|
|
print('DELETE POST:', r2.status, r2.read().decode()[:200])
|
||
|
|
except Exception as e:
|
||
|
|
print('DELETE POST ERROR:', e)
|