diff --git a/readme.rst b/readme.rst index 907f016..abecc8b 100644 --- a/readme.rst +++ b/readme.rst @@ -30,9 +30,3 @@ Goals - Leverage Nim's macro system to produce a framework that allows for the development of applications that are boilerplate free. - Keep it small, keep it fast, keep it flexible. - - -Todo -==== - -- Expose a nice API to do Ajax requests. diff --git a/src/ajax.nim b/src/ajax.nim index 05e9740..d002380 100644 --- a/src/ajax.nim +++ b/src/ajax.nim @@ -31,11 +31,14 @@ proc ajax(meth, url: cstring; headers: openarray[(cstring, cstring)]; ajax.send(`data`); """.} -proc ajaxPut*(url: string; headers: openarray[(cstring, cstring)]; +proc ajaxPut*(url: cstring; headers: openarray[(cstring, cstring)]; data: cstring; cont: proc (httpStatus: int, response: cstring)) = ajax("PUT", url, headers, data, cont) -proc ajaxGet*(url: string; headers: openarray[(cstring, cstring)]; +proc ajaxGet*(url: cstring; headers: openarray[(cstring, cstring)]; cont: proc (httpStatus: int, response: cstring)) = ajax("GET", url, headers, nil, cont) + +proc toJson*[T](data: T): cstring {.importc: "JSON.stringify".} +proc fromJson*[T](blob: cstring): T {.importc: "JSON.parse".}