Designing APIs is an important task. The API should be simple, follow good conventions, behave like expected, be efficient. This post is about updating data in bunch operations.

Lets say you have a blog-system with many authors. On the back-end the authors have a list of all posts and pages. Now they can select many and publish all at once. It is also possible to select a few and change there rating. Actually I don’t want to talk about a blog system. It is about changing many items in a list.

In a standard RESTful-API it is the case that the client will send a patch-request for each of the items. This RESTful approach is simple to implement, in many cases the API can be generated almost automatically. For example you have a MongoDB or MySQL. Using sails.js or loopback you can easily expose an HTTP-REST-endpoint. Also on client side that API can be used very easy. Loop over the selected items, trigger the update-call and handle the response, one by one.

But as comfortable as it is it is also not efficient. When always sending the same information for different entries. In slow connections (mobile, village, shared internet, China), it can reduce the user experience. For this cases the server can provide additional methods to handle bunch operations. like publishPosts many, changeRatingTo. Both methods would in our case expect a list of postIds and the value to change to.

Having a list of Items to change on the server, you have the same question again. Do you execute a single update command on the db or one update after the other. Can you check the permission in as list-operation? Then you can decide, refuse all item-changes if one item fails with some precondition. Last is the result reporting. do you need to send success states for each item, only the success items, only the failing item-changes.

How ever the solution is, that you chose. You should give a transparent report to the user and update the item list accordingly. In the end I want to give you some questions you can ask, when you get the task to implement an API with list operation.

  1. can each item get a different value using this procedure?
  2. fail-one-_fail-all or detailed report?
  3. how should the error reporting look like?

Last time I told you about txml, the fastest XML parser in Javascript.

Now I have a new bonbon for you. tReeact. A framework that is inspired by facebook’s react. In react you are compiling JSX letting you generating an object-tree representing the html-DOM structure. In tReeact you are generating an html-string representing your UI. tReeact will parse that string (using txml) and do the reconciliation, to update the UI and only change the elements that need an update.

This is good, because you can directly reason, why your UI looks as it is, according to your app-data and the generation of the XML. Making updates to the DOM-Elements, it is easy to apply animations using CSS. The XML can easily get created with a templating language of your choice or be send to you from your server.

An important feature are also components. They are used to handle UI-Events. In your app, you can provide some generic components to set a value on click or on change of an input with a direct rerendering. That will provide two-way data-binding between your UI and your app-data.

So the idea and the usage are described quickly. If you like to generate your UI using a templating language of your choice, if you want a separation of your app-logic and the UI development, if you want to handle your UI in a pure procedural way or if you want to build your app with a flux framework, You should give it a try and check it out on Github and npm.

tReeact is a great option, that let you scale from small apps to complex enterprise applications.

It is done, the fastest pure Javascript XML parser is ready.

For a new UI framework that I develop I needed an XML-DOM parser. The new framework tReeact, was highly inspired by react.js but want to to render the UI using a templating language of your choice. The Framework will then update the DOM elements in the Browser, in the fastest possible way and with a minimal amount of direct DOM operations.

But the first step is the XML parser. Usually people make a different of two kinds of XML parser. StreamReader and DOM-Parser. Stream Reader are great to read very large files that are even bigger then a few GB. While parsing they trigger Events describing what was found on the xml-stream. A DOM-Parser on the other hand takes an xmlString and returns an object that represents the structure and data of that XML. Because that object and the entire XML-String have to be in memory while parsing, the size of the parsed xml is limited. There for your program that is using the DOM-Object can be written in a procedural way, not event-driven, what makes it much easier to reason, debug and develop.

The new framework tReeact is meant to handle a web apps UI. And the HTML of an app seldom bigger then 5MB. Thats why tXML became a domParser. The development took serval steps. First I made a basic version that can give nodes, attributes and text content. Then I used this tool to parse different sources. OpenStreetMap, serval websites, there RSS-feeds. I also compared the speed with other projects, like XML2JSON and sax and browsers native XML parser. In the end I was about 5-10% slower in Chrome then native. But the object that I had in the end was a “plane old javascript object”. So accessing the data is much faster then using the DOM API in a browser. That will specially make the tReeact faster, what has to traverse the entire Object to compare.

In other situations the difference will be much more significant. In a direct comparison with sax vs tXML parsing the Github website and a big chunk of OSM-Data the advantage was 5 to 10 times in terms of speed. When reading that, please keep in mind that this is a comparison of a streamReader vs DOM-parser.

Motivated by seeing this advantage, I analysed the tXML parser again. And thought how I can improve the speed and usability for most common cases. A great win for usability was to “simplify” the dom-Object. for that I oriented on PHP’s simpleXML. With a simplify method I return the same object as if it was parsed by simpleXML. This let you access the data very comfortable.

Providing the functions “getElementsByClassName” and “getElementById” the usability as well as the speed is increased. and the speed advantage can be enormous. because you will use this functions direct on your XML-string. In that way tXML parses only the necessary Elements, not the entire XML. These methods make tXML the perfect tool, for parsing Data from any website, that not officially provides an API. So, have fun Hacking the Web.

If you are now interested to use the fastest XML parser, for the best user experience in your application, get started and install the tXML parser with “npm install txml”. or download the standalone version for the browser on github. At NPM as well as on Github, you find the documentation.

A short opinion to the end: if you can chose, use JSON in stat of XML to persist and transfer data, this is much easier to access in all programming languages and also very fast in JS.

The short answer is Javascript. When you want to learn to program, you should learn Javascript. With Javascript you can do almost anything. And today it is getting more and more popular, flexible and useful. It started as a small extension to HTML. But today you can do almost anything with it. It is for sure a great technology to get started with.

If you don’t know now what to program, JS is perfect. If you want to do websites, it is perfect, you want to make iOS, Android or desktop applications, it is perfect. You want to do Server applications, it is perfect. You want to do some script to do some tasks, it is perfect. You want to do some game in 2D or 3d, it is very good. You want to do some Internet of Things (IoT), it is great. You need to handle big data it is great.

My tip, do not try to do class-based programming in JS (for details read object oriented programming is bad)

As soon as you know some javascript. you learned

  • flow control: if, switch, do, while, for
  • variables: var, Array [], Object {}
  • async programming: callback, anonymous function

Often I ask myself why many people can not program. Often I even see developer and think, you can not program right? But actually, I see, that it is not an issue of not being able to code, it is not want to code. And this is reasonable. When people start learning to code, there are some simple and logic examples. Learn variables, loops, conditions, classes, structures, lists but how do I build a GUI? I think this is two totally different things. When you are able to make cool UIs with great smooth effects and a good structure. you learned to make UI and how to use the GUI framework. But using a gui framework has nothing to do with programming, even thou, UI developer are considered as programmer and developer.

But what about algorithms, data structures, software, architecture, communications,…? most of thous things are not necessary when programming today. So, to make a cool app, it is not necessary to know what is a double-linked-list, a B-tree or bubblesort. As a JS developer today you just take array and done. And I think this is good!

But what is it, how to be a programmer? what do you need to say “I can code.”

Actually, I think to say that, one of the above skills is enough. To be able to code is every day a new decision, I want to solve that problem. That problem can be in the UI, Database, in some algorithm. To be able to program it is important that you are motivated and patient to analyse a problem and work out a solution step by step.