It was a wonderful day today. Sunny weather! Something that is quite rare to find in London. It was my 4th attempt on fishing and still there is a plenty of things I need to learn. I am grateful to people managing the Northola fields fishing centre. One of the member even provided me some live bait as I had none. Silly me, I didn’t even ask his name.
Few things that I learned from this session:
Prepare your baits one day before.
Use thin line if you’re fishing in a pond.
Cast in a way so that you make a splashing sound on the water which attracts fish.
Get a catapult if you can to attract fish by throwing baits effectively.
Get comfortable chairs as its gonna be a long day.
Right clothing is a must. (Windproof Jacket, A cap, Shades, waterproof shoes.)
Croydon is a large town in south London, England. It is 9.4 miles south of Charing Cross. It is one of the largest commercial districts in Greater London outside Central London, with an extensive shopping district and night-time economy. [Source: Wikipedia]
Central London is the innermost part of London, in England, spanning several boroughs. Over time, a number of definitions have been used to define the scope of Central London for statistics, urban planning and local government. [Source:Wikipedia]
Four specific things we will be focusing on this article:
Single Page Application
SPA does not only mean faster loading of contents but also has deeper connection with isolation of frontend code to backend code. By creating single page application you start writing your backend code purely in server side because of which you reduce the cohesion already.
By creating SPA you also reduce load to your server. No need to call the server and load the whole page every time you click something. That way you can even reduce the cost by an enormous amount if you are receiving a huge user volume.
APIs are not a new thing. If you can remember using a login page where you enter your details and see an error without refreshing the whole page then Yeah! thats when you saw an API being used.
But the term RESTful is different. REST determines how the API looks like. The URL, Request Body, Response Body, Request Method and so on. You need to follow the standards to say that you have build a RESTful API.
By developing your web application through API based approach, releasing new versions or updates becomes far more easier.
Although following best practices can be difficult in many cases, building your application through API first approach should be your major priority. With API based approach of development you are already separating your frontend with your core backend logic which not only has one but many many benefits like testing those layers separately, route based load balancing and many more.
By following RESTful practices most of the APIs are self documented as well. For example; if you wrote a POST method that means the API is responsible for creating new data similarly GET, PUT, DELETE are self explanatory.
Now after having your web app developed and ready for deployment next comes the question of choosing the right deployment platform. Popular web host services like Bluehost, Godaddy etc provide pre-configured server environments with PHP, Python, MySQL. The problem with these hosting is that the versions and the additional libraries you install them are manually done and aren’t documented anywhere.
Documentation is key to success.
This is where containerisation comes in action. You need to write down each and every step of what you require in your server. Docker has been the number one choice to build & run containers.
With my years and years of experience in web development, one thing that I have noticed is developers tend to create logics so complicated, a function or a class that is literally responsible to do everything. This is a bad thing to do.
Tight coupling is a bad design.
Micro-service is a concept of physically isolating the features of an application. That way each feature or a service has to talk to each other through mediums like APIs or Message Queues or something similar. They cannot directly interact with each other through hard coded logic.
Web is a rapidly progressing technology sector. Every month there is something new evolving to become better or something new being introduced to add value. My suggestion is do not panic because of the introduction of new tech stack but instead admire the passion of people for creating these amazing new technologies to make things easier and efficient.
Below function/procedure will create a csv file for each table in the database.
CREATE OR REPLACE FUNCTION db_to_csv(path TEXT) RETURNS void AS $$
FOR tables IN
SELECT (table_schema || '.' || table_name) AS schema_table
FROM information_schema.tables t INNER JOIN information_schema.schemata s
ON s.schema_name = t.table_schema
WHERE t.table_schema NOT IN ('pg_catalog', 'information_schema')
AND t.table_type NOT IN ('VIEW')
ORDER BY schema_table
statement := 'COPY ' || tables.schema_table || ' TO ''' || path || '/' || tables.schema_table || '.csv' ||''' DELIMITER '','' CSV HEADER';
$$ LANGUAGE plpgsql;
Simply run the select command which will create file in provided path. Remember to provide chmod 777 /your/path so that the folder is writable.
If you’re creating this inside a docker container use following command to copy it from container to host: