@inherits Custom.Hybrid.Razor14
@{
// Tell the page that we need the 2sxc Js APIs
Kit.Page.Activate("2sxc.JsCore");
}
<!-- unimportant stuff, hidden -->
Very basic WebApi Examples In this... <!-- unimportant stuff, hidden -->
<button type="button" class="btn btn-primary" onclick="getOrdersFetch(this)">Quick Fetch GET "Orders"</button>
<script>
// Fetch using modern Browser APIs
// This is the more manual method, in case you don't expect JSON or want more control
// This uses the full internal syntax `app/auto/api/controller/method`
function getOrdersFetch(moduleContext) {
$2sxc(moduleContext).webApi.fetch('orders/get')
.then(response => response.json())
.then(data => alert('Result using quick Fetch: ' + JSON.stringify(data)));
}
</script>
<button type="button" class="btn btn-primary" onclick="postOrdersFetch(this)">Quick Fetch POST "Orders"</button>
<script>
// Fetch using modern Browser APIs
// This is the more manual method, in case you don't expect JSON or want more control
// This also uses the shortest API syntax `controller/method`
function postOrdersFetch(moduleContext) {
$2sxc(moduleContext).webApi.fetch('orders/post', { amount: Math.floor(Math.random() * 100) })
.then(response => response.json())
.then(data => alert('Result using quick Fetch: ' + JSON.stringify(data)));
}
</script>
<button type="button" class="btn btn-primary" onclick="putOrdersFetch(this)">Quick Fetch PUT "Orders"</button>
<script>
// Fetch using modern Browser APIs
// This is the more manual method, in case you don't expect JSON or want more control
// This also uses the shortest API syntax `controller/method`
function putOrdersFetch(moduleContext) {
$2sxc(moduleContext).webApi.fetch('orders/put', { amount: Math.floor(Math.random() * 100) }, 'PUT')
.then(response => response.json())
.then(data => alert('Result using quick Fetch: ' + JSON.stringify(data)));
}
</script>
<button type="button" class="btn btn-primary" onclick="deleteOrdersFetch(this)">Quick Fetch DELETE "Orders"</button>
<script>
// Fetch using modern Browser APIs
// This is the more manual method, in case you don't expect JSON or want more control
// This also uses the shortest API syntax `controller/method`
function deleteOrdersFetch(moduleContext) {
$2sxc(moduleContext).webApi.fetch('orders/delete', null, 'DELETE')
.then(response => response.json())
.then(data => alert('Delete executed'));
}
</script>
<!-- unimportant stuff, hidden -->