Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Full Stack Development From Client-Side JavaScript [No Node.js]

DZone's Guide to

Full Stack Development From Client-Side JavaScript [No Node.js]

We take a look at one developer's experiment, where he hopes to create a way to code a full stack app using only client-side JS.

· Web Dev Zone ·
Free Resource

Jumpstart your Angular applications with Indigo.Design, a unified platform for visual design, UX prototyping, code generation, and app development.

In case you think the above header sounds like an oxymoron or some sort of black magic, think again. With Lizzie, you can (at least in theory) create your entire business logic in JavaScript, in your browser, submit your Lizzie code to the server for evaluation (securely), and have it return JSON back to your client.

For the record, this assumes you've previously created generic "hooks" in C#, allowing your Lizzie code to do something useful, since, out of the box, Lizzie can barely do anything at all, besides from creating lists, dictionaries, do basic math, and some simple string manipulation. However, if you create generic methods for retrieving data from your database, etc., creating your business logic in JavaScript as Lizzie code, and transmitting this code to your server for evaluation, is actually a breeze. This in turns creates a much more dynamic server-side API, allowing you to (after a while) do anything you want from JavaScript, without having to code in (any) server-side language at all. At least that's how the theory goes. To understand what I am talking about, picture the following code.

[Route("api/[controller]")]
public class LizzieController : Controller
{
    [HttpPost]
    public string Post()
    {
        try
        {
            using (var reader = new StreamReader(Request.Body))
            {
                string code = reader.ReadToEnd();
                var lambda = LambdaCompiler.Compile(this, code);
                var result = lambda();
                return result?.ToString() ?? string.Empty;
            }
        }
        catch (Exception err)
        {
            Response.StatusCode = 500;
            return err.Message;
        }
    }

    #region [ -- Lizzie functions -- ]

    [Bind(Name = "howdy")]
    object Howdy(Binder<LizzieController> binder, Arguments arguments)
    {
        return "Hello " + arguments.Get<string>(0);
    }

    #endregion
}

The beauty of the above C# Web API code is that the endpoint accepts CODE as input. This allows you to create a single HTTP REST endpoint, accepting code over a POST request, that will evaluate your code (securely), returning JSON back to the client.

Which again effectively allows you to (at least in theory) create your entire application in client-side JavaScript, connecting to a "generic" backend, reducing the server to a simple "Lizzie evaluator," making it possible to create arguably your entire web app in Angular, React, etc. Below is a screenshot of a simple example application I created with this pattern, that allows me to type code into a CodeMirror instance in my browser, send my code to my server, evaluate the code, and display the results of the evaluation in another CodeMirror instance.

Image title

The above project can be downloaded here.

Take a look at an Indigo.Design sample application to learn more about how apps are created with design to code software.

Topics:
full stack developer ,c# ,web api ,web dev ,javascript

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}