-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
74 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
title: ts-json | ||
---- | ||
|
||
# `ts-json` {.text-center} | ||
|
||
The `ts-json` attribute is designed to handle multi-level nested data | ||
structures in JSON format that are not possible with `ts-data`. | ||
|
||
When a request is triggered, TwinSpark will use the `ts-json` attribute | ||
to directly parse the JSON string from the originating element and will | ||
set the `Content-Type=application/json` request header. | ||
|
||
There are a few limitations to note with `ts-json` compared to `ts-data`: | ||
- Attributes under `ts-json` do not merge. | ||
Each `ts-json` represents a standalone dataset. | ||
- Requests utilizing `ts-json` cannot be batched. | ||
|
||
|
||
{{ template "examples" . }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
id: json | ||
title: Request JSON API | ||
tags: ts-json | ||
---- | ||
<p> | ||
Simple <code>POST</code> request with JSON body. | ||
</p> | ||
|
||
<div class="card example"> | ||
<div class="card-header"> | ||
<h5 class="d-inline mr-2">Demo</h5> | ||
<button class="btn btn-link btn-sm reset">Reset</button> | ||
<button class="btn btn-link btn-sm source">View Source</button> | ||
</div> | ||
|
||
<p class="card-body"> | ||
<a href="/data" | ||
ts-json="{"user":{"name":"Sanya"}}" | ||
ts-req | ||
ts-req-method="post">Send!</a> | ||
</p> | ||
|
||
<script> | ||
XHRMock.post("/data", function(req, res) { | ||
return res.status(200) | ||
.body( | ||
'received: <span>' + req.body() + '</span>'); | ||
}); | ||
test(async (el, t) => { | ||
el.$('a').click(); | ||
await t.delay(1); | ||
let res = decodeURIComponent(el.$('span').innerText); | ||
t.assert(res == '{"user":{"name":"Sanya"}}='); | ||
}); | ||
</script> | ||
</div> |