Back to Website

Web API: A Song of Trial and Error

Posted September 1, 2016 at 1:12 PM by Ben

The Middle Man

It is easy to leap from input to output when it comes to data.  Anyone could draw a bar chart based on a spreadsheet.

When anyone does that they become the equivalent of a Web API without knowing it.  They look at what needs to presented, they trawl the spreadsheet for the correct group of information and then return to the bar chart and with that information in hand.  Only then can someone begin to work.

I've written posts about the front end of a Web Service, a variety of situations involving data, I've written about retrieving data from an API that I have then used to overlay information on a Google Map. 

You can probably see where this is going, I've used them, designed things with the use of an API in mind.  Until recently however I hadn't rolled my sleeves up and built my own.  I made many mistakes, turned out builds that were completely and hopelessly inept at their desired function.

Now, however I have something that works exactly how I want, something that can do the whole range of Create, Read, Update and Delete (CRUD).

Lessons Learned

The Big One

Direction is really important, it's no use setting out to plan and build a Web API without being at least 95% sure of what it needs to do for you and anything that interacts with it.

I'm close to doubling down and posting a multi-part overview of the project this API was built for.  The mistakes and successes of that work came very much so due to initially having a poor idea of what I wanted and needed to build, that was the entire project and not just the API.

By meticulously planning out the source of your data and what the final product of your API needs to be you can save yourself an astounding amount of pain and frustration, never mind the dozens of StackOverflow visits every hour when your API isn't behaving the way you need it to.

Mistakes are going to happen. Embrace them.

At various points throughout building this API I made amateur-hour mistakes.  The code review was full of disbelief at some of the poor approaches I took to achieving the desired effect within Controllers or Models in the API.

At the time, these methods were operational, they definitely worked how I wanted it to do things, looking back now I can shake my head in disbelief as well. Refactoring code is hard when you don't know better ways to approach things and more often than not the best way to learn is to fail.  You're failure is only complete when you don't learn from it.  In this case it wasn't a case of a slight misuse of a method that could have been solved another way, it was a complete failure to understand manipulating data in a correct and clear way.

On to the good stuff

This Web API takes HTTP calls to do it's work.  POST, GET, PUT and DELETE. These correspond to the CRUD functions.

POST sends a JSON object containing all of the information that a record holds, this object is built from user inputs to create a new record in the database.  When the JSON object arrives it maps itself to the "Update" object and it's properties and that object is then used to construct an INSERT statement in the database and write a new record.

GET retrieves a group of 15 records from a database when given a page number and delivers those back to the web page to be displayed in a table.  Each of these 15 records is added to a list of Record objects and they are then returned to the webpage as a JSON object.

PUT receives a specific record, however that record comes with new information that the API must tell the database to update with.  As with POST this JSON object is used map a new Update object that in turn is used to construct an UPDATE statement where the UpdateID of the record is passed in the WHERE clause to change that record only.

DELETE receives one thing, the UpdateID of the record the user on the front end is trying to delete, a simple DELETE statement WHERE the UpdateID is matched is deleted, this is unique across the CRUD functions of the API as doesn't require any objects to be constructed, the only thing being passed in is an int value.


With ASP.NET there is an option to change how API calls work from the front-end.  In the case of this particular API, first the API's host is listed, then the API, then the controller, then the method. Optionally the user can pass in an integer at the end of this call as data.  A final URI (Uniform Resource Identifier) would look like such: "".

This URI would result in the API deleting the record with an ID of 4.

Routing is controlled by the designer of the API, I could have set up those URI components in any order I wanted just to mess with people but alas such things are frowned upon.

The worst possible Analogy...

I spent far too long thinking of a way, in layman's terms of how I feel about the interaction between a Web API and the Front End it is being used by.

So, imagine if you will that the front end is a screw and the API is a screwdriver.  You have the screw you want to use and you look into your toolbox to see what screwdriver will get the job done.  If you reach in blindly and pick out the first screwdriver you find, you've got a pretty big chance that it won't work, a small chance of picking out something that will do the job adequately and an even small chance of nailing it first time.

Understand that this works both ways, if you're using a Web API that has been around for years you may need to change the screw to get the front end to work.

The better a match for your Front-End the API you use or design is the less hoops you have to go through to get to where you need to be.  It's always worth checking out alternatives to see if what you're using isn't what's right for the job.


It's a weird and wonderful thing to be at the stage of my training where I can be asked to visualise, plan, design and code a full web service, albeit a fair amount of poor work going into that service.  It's in equal parts a measure of how far I've come in the past year and of how much more ground there is to cover ahead as I go on from here, there are new things to learn in C# every time I try something new.  As I often repeat myself saying, it is up to me to try to cover that ground moving forward.

One full year, it's hard to think about the sheer density of things that have happened both in work and personally over that time since I first turned up to Antelle.  I'd like to think good things about that time for the most part, ignoring the flooding of our old office of course. I prefer to look back on struggling with the first HTML assignments, of getting my first web page finished just a few months later.  I think I'm settled and in a position to push myself further and start helping with other projects more, to see more of how the most complex projects are designed and planned.

Until the next time, thanks for reading.

C# and becoming Trilingual

Posted May 19, 2016 at 12:36 PM by Ben

Show Antelle

Get it?

Anyway, I took part in my first demonstration to a client of a product, the product in this case being the close to finished version of the Umbraco website I mentioned in my last blog post.

Bugs, bugs everywhere.

I was surprised at how, despite my best efforts to try and break my own work, it only takes one person saying: "What happens if I do this?" and everything seemingly comes apart at the seams. To detail a few things; the navigation bar had an odd bug that would add random empty unordered sublists after certain pages, the CSS controls I added to prevent certain content elements from breaking the page didn't do as much prevention as I had hoped and the responsive page sizing wasn't quite as perfect as it could have been.

That said, if the presentation had gone perfectly and these errors hadn't been found, my first real published product would have been fraught with minor bugs, which I'm obviously pretty eager to prevent.  So a bit too much pointing at a screen and saying: "Yes I'll fix that as soon as we're done." did have some positive effects.

As well as exposing bugs, I got some valuable one on one insight into how the customer wanted certain things to work, whether that was more CSS controls for him to use in controlling the content via Umbraco or a minor aesthetic tweak to how the header would display.

I'm confident that when the website is released he will be very happy with the final result, featuring the lovely clean look of Bootstrap and the capability to fit on any screen, big or small.

Sticking to the Program

The road map for my time at Antelle now has me firmly into learning C#, a universally used and extremely powerful language that is opening my eyes to the power that words in a file can apply to the real world.  So far I've only dipped my toe in the proverbial pond of C# and it's been a blast so far.

I think Tony has been reading over my last blog post and saw that I what I said about my learning process and promptly handed me a task to solve.  As I write this I've "finished" a small program that takes an XML file containing various queries to be passed to SQL Server and returns data that is then converted into a CSV format.

Making this program has taught me two important lessons at the very least:

Bigger isn't always better, at various times throughout making my first actually useful C# Tool I tried again and again to over-encapsulate my work, most of my source control comments at the mid point of the Tool's history tend to be:

"Added working classes for XYZ"
Shortly followed by:
"Working classes for XYZ removed, pointless"

Through learning resources it was emphasised again and again how important it was to try and use classes to make everything organised, to encapsulate things as it is a good practice for C# developers.

While this holds true for much, much larger programs than my own.  It only ended up confusing me by making a Class with very little too it and then referencing three class in a row in my main program, with something this small it really is not necessary to over-encapsulate.

The other thing I learned is that if I'm looking to add something to my program, odds are that someone far more talented than me (for now) has already made a framework for it.  In this case it was logging errors to the Event Log. I tried to do it on my own for a brief period, resulting in some humorously mind boggling issues with eternal errors refusing to ever stop being passed on.

So, I switched to a framework at the behest of Tony, and no surprises with what happened next, my work was done far, far quicker.

Thanks for Reading

Come back for more ramblings soon!


Exam Success, Umbraco and Looking Forward

Posted April 22, 2016 at 12:26 PM by Ben

Normal Service Resumes

As fun as 14 hours in the Hospital was, the recovery is always so much more entertaining.  Three weeks after some well-qualified men and women poked and prodded around my knee, I was back to 100%.  Which means I was in a good state to take my Database Fundamentals Exam.

Which I passed, narrowly, but a pass is a pass.

Despite my worries, I appear to have done well in the areas I felt I was lacking somewhat.  There is nothing like entering a new skill set with no idea what you're doing and coming out with some vindication of your ability in it afterwards.  Which brings me on to some newer work.

Umbraco's Razor Sharp Edge

As I was building up to my Exam I was building a website larger than any I had tackled before, featuring three candidates for the client's perusing and building upon the chosen one.  It took some time but I built a website I was very happy to present and then I chose to take on the responsibility of converting my work to Umbraco, a Content Management System.

That didn't mean I was ready for it.

Technically the roadmap set out at the start of my Antelle career would dictate I would begin learning C# as soon as I passed my Database Fundamentals Exam.  This Umbraco work is certainly part of it.

I'd like to go on a brief tangent:

When I was learning HTML/CSS/Javascript, I would take on a problem and then learn the way to break the problem down and solve each piece of the puzzle with a new piece of knowledge.  I found this to be an incredibly intuitive way to learn new aspects and go further than just learning, but really understanding how different roads may lead to the same castle, but some roads are more efficient in a context.

On the other hand, as I was learning Databases I often failed to give myself problems to solve.  I would trawl through the internet and other sources of information to learn a new command, a new concept involving data.  However, I would then fail to compound my theoretical knowledge with working knowledge.  That meant for a long time I wasn't "gettting" how things would work.  For a brief period my co-workers would give me a scenario, problems to be solved like when I was learning Web Design.  Giving me the working knowledge and understanding I feel has led to me being able to pass the exam.

So to bring this back to Umbraco and C#:

Going in with the brakes cut has led to me requisitioning help from Sam, who has been an vital part of letting build my working understand of Umbraco and my first steps into C#.  More importantly it's given me an excellent perspective on the scope of the language and the power that relatively little code can have compared to other languages.  Understanding my own learning process will absolutely give me perspective on how to help as the Antelle Academy marches on.

Umbraco has helped ease me into the deeper workings of professional web design, where I am not just building a website, but learning how to manage one as well.  Technically the site is still in progress, but the moment of truth draws closer by the day.  It's a powerful tool that I am more capable now for having begun to utilise it.

A Strong Independent Trainee Developer

Moving forward on my own after Joe's departure has definitely been a mixed bag, it's sometimes difficult to judge if my progress and work rate is to a good standard now that I have no one to compare myself to, although I try hard to not let there be question about i.  I occasionally miss being able to have a ready second opinion on where to start and stop when I work.  It's been a short section but I felt that it needed to be included.

A Whole New World

We now have the whole office complex to our little old selves, which was unbearably empty, so Tony bought a ton of office equipment.  Now I'm not sure when I opened my mouth and said anything about being good at DIY or if it's newbie privilege but I ended up assembling it all, it now looks stunning and built all to a perfect standard, but I'm not biased, really.

The final count of assembled items includes three office desk with pedestal drawers, two folding desks, two cupboards (one big, one small) and two office chairs, not bad really.

Some reshuffling has taken place and Tony has moved into the big office around the corner, I'm assuming this is because he couldn't take staring at me all day, although that's as good a reason as any.

Moving On

Once I wrap up the Umbraco Site and get that out the door I'm back to the wonderful world of not knowing anything about the next subject, I do feel that my experience in learning two other areas of programming has given me a better idea of how to maximise my learning and blitz through to the next exam.  I am hearing mutterings and whispers of 18 months of C#, so I might even be pretty good at the end of time.

I feel the ship has steadied completely after the floods and we can press on as a company.  I feel like I can be of some use now (and I don't mean being the desk assembler) and that's giving me a good boost to do better and try harder than ever to progress and repay the faith shown in me by Antelle.

Until the next time! (hopefully not another two month gap next time)


Update (The One with the References)

Posted February 19, 2016 at 12:13 PM by Ben

The Lone Wanderer

They say all good things must come to an end.  Unfortunately my previous partner in crime left the big brother house of Antelle not to long ago.  I was sad to see Joe leave, a good worker who had a good mind for the tasks we undertook.  Although, I know as well as anyone that when something is just not quite right that it’s better to walk away sooner rather than later.  I made a similar decision almost exactly a year ago that started a series of decisions that eventually and thankfully led to me typing out a blog post from the Antelle Academy.

Moving forward as a single person instead of as a pair is going to change a few things, good and bad.  Maybe I won’t have someone on the same track to bounce my crazier ideas off but, if I’m honest, I think the other workers will come to love such a charming personality spouting ridiculous ideas.

If you read this, best of luck Joe, the banter hasn’t quite been the same.

Passing Exams

On to more positive topics, I passed my first exam at the second try.  I am officially a Microsoft Certified Professional.  As nice as being able to say that to strangers and get a mute reaction or a raised eyebrow.  It’s just the start of a long journey to Developer-dom that is certainly helping fill me with determination to kick on with my current path.

Technically I walked out of that exam no more or less capable of working HTML/CSS/JS than I was going in, I just had a shiny badge saying I know what I’m doing to an extent.  One or two low profile websites later and maybe I also feel better about saying it too.

While that exam is the final step on a fast track course in web design as Antelle outlined.  I don’t think for one second that’s going to be the end of my learning in the area.  Working with combining web design with back-end operations as is the bread and butter of most web developers and is going to take more learning on my own as I move forward.

I’m definitely going to file Web Design away for the time being, I’ll talk about my current focus in just a second.  For a last word though, I think that HTML/CSS/JS is one of those things that anyone can learn, it’s up to me to invest the time not just in the future, but consistently for the rest of my career to be really good with it.

A long awaited SQL

I’m sorry (not sorry) for the pun, but it’s too good to pass up.  A second quarter comes around and it’s time to march on with Structured Query Language, but for the sake of sanity let’s keep it to SQL.

For people new to SQL, there are really two sides to what you have to learn.  It’s not just learning the language, the syntax or the little combinations that help you do amazing things in short little lines of code.  You have to forget everything you think you know about the storage of data.  Odds are, if you are anything like I was two months ago, you probably think all the data belongs to Microsoft Excel and it’s spreadsheets.

Oh boy, it’s a doozy to get your head around occasionally.

You must unlearn what you have learned

It’s not often I can drop this many references so I’m not going to apologise.  Anyway, data in the traditional sense (at least the way I thought about it before enlightenment) is stored as an object, a thing that has something about someone thought would be important and decided to measure it. So picture your spreadsheet,  at the top it’ll say “Thing” and down we’ll go, listing all the properties and we can know everything there is to know about “Thing”.

Great, right?  Why on Earth do we need anything else?

Because spreadsheets are like a complete SQL Query,  look at that nice dataset, it’s interesting.  However, what happens when you want to know more?

You go find a different query, one that’s going to give you the data you want.

Databases in SQL are built of tables, these tables are templates almost, if the dbo.Car table has an ID column, a name column and a colour column.  Then every single car in that table is going to have data on the car’s ID, Name and Colour.  What’s important about this is that when we request data, we can ask for cars that are only red to be displayed or cars with an ID higher than 64.

When data is stored in tables, you can be as specific as you want.  You can make broad statements and receive lots of data, you can really get specific and get only 1 or 2 entries.

So tables are pretty cool.  So what happens when you want to find out who has the car with ID of 6?

You join the tables together.

Literally, it’s called a join, it’s great.  For as complicated as SQL feels sometimes, it’s fairly good at doing exactly what it says on the tin.

Without diving too far into a rabbit hole that anyone new to SQL will be hopelessly lost in, the principle of a join is that any table that can share a common column will have data that will ‘slot’ together.  Again, that is a vast oversimplification and is ignoring so much but it’s not really necessary to go that far.

So we have our Car table, let’s get that extra data.  Let’s say there is another table, let’s call it dbo.Person, it has IDs, Names, many important things and most importantly, a column called CarID, perfect.  

We can ask SQL to do a join. It will line up that car with an ID of 6 to the Person with CarID of 6.  Now we can find out that Person with CarID of 6 was born in 1997 and that his favourite colour is purple.  Which definitely explains the ghastly colour of Car 6.

Joining Data together let’s us have more data together at once.  It’s not all there is to SQL, not by a long shot I’m afraid.

It is a good pain

Finally solving that problem that is, slaving away to find the best and most efficient way to find out the average age of everyone that drives a Fiat, or the average age of a car against people who were registered on the database last month.

It’s something I won’t explain to much, but I can attest to the elation of finding the right answer to a query that I’ve been asked to put together as a test of my progress.  If you want to have an outpour of excited, fidgety and clear explanations of a concept you don’t quite understand, just ask a developer who’s just finishing finishing up a big query in SQL involving that concept.  


Progress is coming along with SQL, most definitely.  I have an exam date pencilled in and it’s coming up quickly in the grand scheme of things.  Here’s hoping I’m ready.

A New Home

I thought I’d give the time to show some appreciation for the new digs, we’re now set up on the upper floor of a nice office. Which at the very least will give protection from a repeat flood performance if not the inevitable heat death of the universe.

Barring an occasionally temperamental heating system the new office is amazing.  Some upcoming time on crutches is going to make those stairs a bit more annoying but that is the price you pay for beauty.

Cosy and spacious at the same time, our current set-up allows us to communicate really easily while also preventing distractions all at once.  A hard balance to strike in my humble opinion.  Best of all it seems we’ve just got back to business thanks to the fanatical hard work of Tony to get us up and running again.

To be Continued…

There are a number of things happening soon that I could have written about here, instead I think I’ll make a promise to get a dedicated blog post up shortly after these things have been truly set in stone.

It’s been a odd period that began with me being knee deep in flood water and ends with me sitting here about to embark on a singular journey onward.  It’s been a long post but I think I could be writing for two, at least for the time being.

Thanks for reading, and have a good day.

Our Commitment

We strive to deliver a level of service that exceeds the expectations of our customers.

If you have any questions about our products or services, please do not hesitate to contact us

Microsoft Silver Partner in Application Development

Stay Connected

Antelle IT Ltd
Unit 17b
Carrs Lane
Tromode Estate
Isle of Man

Phone: +44 (0)1624 660613