Sunday 15 April 2018

Upgrading to ASP.Net Core 2.0




Microsoft has already released version 2.0 of ASP.Net Core along with .Net Core 2.0. .Net Core 2.0 enables developers to avail several new class libraries and over 20000 new application programming interfaces (APIs) by supporting .Net Standard 2.0. The developers can upgrade their existing applications to ASP.Net Core 2.0 to take advantage of the new APIs supported by .Net Core 2.0. Also, they can write high quality code by availing the new language features provided by C# 7.1. At the same time, ASP.Net Core 2.0 also comes with several new features and improvements.
It comes with a new coding paradigm called Razor Pages. The developers can use Razor Pages as a page first structure and a lightweight alternative to ASP.Net MVC. Razor Pages allows programmers to create razor views based on PageModel without using controllers. Also, the coding paradigm contains the entire code for a specific page in a single file. Hence, developers can upgrade their existing applications to ASP.Net Core 2.0 to take advantage of the new features and APIs. However, the developers must keep in mind some simple points while upgrading from ASP.Net Core 1.x to ASP.Net Core 2.0.
Important Points to Consider while Upgrading to ASP.Net Core 2.0
Deciding the Right Way to Upgrade
Microsoft allows developers to upgrade existing applications to ASP.Net Core 2.0 in two distinct ways. If the application is developed by targeting .Net Core 1.0, the developers can upgrade it simply by upgrading the targeted framework to .NET Core 2.0.  They need to change the innertext of the <TargetFramework> node to netcoreapp2.0 in the .csproj file. On the other hand, the developers have to install the version 2.0 of .Net Core along with ASP.Net Core 2.0 if the application is developed without targeting .Net Core.
Upgrade the Package Reference
In version 1.0 of ASP.Net Core, the .csproj file lists the Nuget packages used by the project individually. ASP.Net Core 2.0 replaces the collection of individual Nuget packages with a single metapackage reference called Microsoft.AspNetCore.All. The metapackage reference includes the core packages of both ASP.Net and Entity Framework, along with additional dependencies required by the programmer. Hence, the developers have to update the package references while upgrading the existing application to Microsoft.AspNetCore.All.
Update the Main Method
While using, the programmers can take advantage of a simpler Main method in the Programs.cs. The simplified Main method even does not require programmers to write additional lines of code. Hence, the developers must update the Main method of the Programs.cs file while upgrading from version 1.x to version 2.0 of ASP.Net Core. The updated Main method will enable developers to take advantage of the new features provided by ASP.Net Core 2.0 and work with Entity Framework Core 2.0. Also, the developers can avoid a number of coding errors by updating the Main method.
Update the Startup Class
In addition to updating the Main method, the developers also need to update the Startup class while upgrading to ASP.Net Core 2.0. They are no longer to set up Logging and Configuration as part of the Startup class. Instead, they have to move the move the Logging and Configuration setup to the simplified Main method. They can even use the WebHostBuilder to add both Configuration and Logging to the Program class. The option enables ASP Net developers to use Configuration and Logging as core services while working with ASP.Net Core 2.0.
Additional Configuration Changes
While upgrading to ASP.Net Core 2.0, the developers need to version attribute of various .Net Core command line interface (CLI) tools to 2.0.0. They have to update the changes by modifying the <DotNetCliToolReference /> node. Likewise, the developers also need to rename both name and variable in the <PackageTargetFallback> node to AssetTargetFallback. They also have to invoke Entity Framework 2.0 commands to upgrade the database initialization code and obtain the application services. As ASP.Net Core 2.0 enables Razor View compilation by default, the programmers are no longer required to set the MvcRazorCompileOnPublish property as true. But they still need to target the specific Nuget package to configure Razor View compilation accurately.
On the whole, developers must upgrade their applications to ASP.Net Core 2.0 to avail several new features and APIs. But they have to focus on a number of factors to upgrade the applications seamlessly from ASP.Net Core 1.x to ASP.Net Core 2.0. Also, they must refer to the migration guide provided by Microsoft to understand the best way to upgrading to ASP.Net Core 2.0.

Tuesday 13 March 2018

Best practices in PHP for 2018




The relevant and popularity of PHP as a server-side programming language will remain intact in 2018. According to the latest usage statistics posted on several websites, the latest version of PHP is currently being used by less that 10% of all websites. Most web developers will switch to PHP 7.x in 2018 to build web applications that run faster and consume less memory. Likewise, the developers will execute PHP code through various micro and full-stack web frameworks to build custom web applications quickly and efficiently according to varied business requirements. At the same time, the developers will implement a number of PHP coding best practices to keep the code base clean and the web application maintainable.
7 PHP Development Best Practices Web Developers Must Implement in 2018
1) Choose Coding Style according to PHP Framework or Libraries
Web programmers can format and share PHP code more efficiently by using various coding styles – PSR-1, PSR-2, PSR-3 and PSR-4. He can use the coding styles interchangeably. But the latest version of the coding style may not support some of the coding standard included in the latest version. Also, the coding style followed by individual PHP frameworks and libraries differ. Some of the PHP web frameworks and libraries even do not follow the latest coding style. Hence, the developers need to use the coding style followed by the web framework and libraries used by the specific project.
2) Manage Project Dependencies with Composer
It is also important for web developers to choose the right PHP libraries and manage them efficiently. The developers can easily manage various PHP libraries and their dependencies by using a robust dependency manager like Composer. Composer is designed as an application-level package manager for PHP. It even simplifies dependency installation and management by providing standard methods. They even have option to run Composer through a command-line interface, and manage dependencies by running specific commands.
3) Use PHP Debug Bar to Debug Code Efficienty
In addition to writing clean and maintainable code, the PHP programmers also need to find and repair all errors in the code. They must explore ways to debug the PHP code efficiently to locate and repair all errors in the code. The PHP developers have option to choose from a wide range of debugging tools. But they must consider using PHP Debug Bar to identify the coding errors quickly based on the profiling information displayed at the bottom of the page. They can even install PHP Debug Bar without putting extra time and effort. Also, PHP Debug Bar can be integrated seamlessly with various projects.
4) Explore Ways to Use Service-Oriented Architecture
Service-oriented architecture (SOA) helps developers to build websites with services or functions which can be invoked by clients regardless of the device, operating system, or programming language. Despite being platform-independent, the services or functions make web applications deliver richer user experience by facilitating data translation and improving information flow. There are a number of PHP web frameworks – Laravel, Yii, Zend and Symfony – that enables web application developers to use SOA. The PHP developer must use one of the HTTP-centric web frameworks to build web applications with components that run independently while interacting with each other seamlessly.
5) Optimize Database Operations
While writing PHP code, programmers often ignore the significance of optimizing database operations. They must optimize database operations while writing code to improve the PHP application’s speed and performance. The PHP programmers can easily make the web application consume less memory by closing database connections in the code. Likewise, they must explore ways to make the application run faster by not hitting the database frequently. They can write comprehensive SQL queries to perform common database operations without hitting the database frequently. At the same time, it is also important to identify and update the slow SQL queries to make the web application access resources quickly and smoothly.
6) Opt for JSON Data Format instead of XML
While writing web applications in PHP, a programmer has option to choose from two used format for data exchange – JSON and XML. But he must remember that XML uses more words than JSON. Also, JSON parses data much faster than XML. The developer can even accelerate parsing by availing the built-in functions provided by PHP – json_endcode and json-decode. They can use json-encode function to return the JSON representation of a value and json-decode to decode a JSON string into a PHP variable. If a PHP programmer prefers XML to JSON, he must use regular expressions instead of DOM manipulation for data parsing.
7) Adopt Test Driven Development through PHPUnit
Unlike conventional software development practices, test driven development (TDD) allows developers to write code only after an automated test fails. Hence, it becomes easier for developers to deliver high quality web applications by writing readable code and avoiding code duplication. PHP does not provide any built-in feature to facilitate TDD. But the PHP programmers can easily implement TDD by using a robust programming-oriented unit testing framework like PHPUnit. The features provided by PHPUnit will make it easier for programmers to define and run tests before writing code.
In addition to implementing these development best practices, it is also important for developers to pick the right PHP web framework. The full-stack web frameworks for PHP makes it easier for programmers to build large and complex web applications by providing several advanced features and tools. But the additional features provided by the web framework often impact the web application’s performance and speed. Hence, the PHP programmers must spend some time in evaluating the pros and cons of individual web frameworks based on precise needs of each project to build PHP applications that run faster and deliver richer user experience.


Monday 26 February 2018

What Do Web Developers need to know about REST API?


While developing modern web applications, developers explore ways to make them communicate seamlessly with various applications and services. The application programming interfaces (APIs) make it easier for programmers to make web applications communicate with various applications and services without writing additional code. Each web developer can even add specific functionality to the web application by choosing APIs from various categories – shopping, social networking, mapping, search, mapping and telephony.
A REST API or RESTful Web Service is developed based on Representational State Transfer (REST) technology. REST is stateless and cacheable client-server architecture. Many websites and web applications use REST APIs to communicate with other applications and services through various HTTP methods – GET, POST, PUT, DELETE and OPTIONS. HTTP protocol enables web developers to work with several widely used platforms and programming languages. Also, the developers can accelerate web application development by keeping the front-end and back-end separated.

Understanding Important Aspects of REST API
Developed Based on REST Architecture

As its name indicates, a REST API facilitates client server communication based on REST technology. REST is a stateless but cacheable technology. It enables developers to use REST client to access and present the resources provided by REST server. They can even identify individual resources like text, XML and JSON by their unique URIs or Global IDs.
Unique Characteristics

Unlike other APIs, a REST API must adhere to the key constraints of RESTful architecture style. The constraints of REST architecture styles make REST APIs different from other APIs. A REST API needs to be designed based on key constraints like stateless, cacheable, and client-server. The web application developers need to use a client to handle frontend and a server to handle the backend functionalities. But they have option to keep the client and server separated. Likewise, they can enable the client to cache responses, but cannot store any data on the server between two requests.
Access Resources through HTTP Standard Methods
REST technology used HTTP protocol for data communications. While using a REST API, the developers can treat each component as a resource. Also, they need to access the resources through HTTP standard methods like GET, POST, PUT, DELETE and OPTIONS. For instance, they can use PUT for creating new resources, POST to update existing resources, GET to provide read-only access to resources, and DELETE to remove resources.
Use Open Protocols and Standards
A REST API is developed as a collection of open standards and protocols. The developers can use REST API to make a web application interact with various applications and systems through open protocols. The open standards make it easier for programmers to facilitate communication between applications written in different programming languages. Likewise, the programmers can use REST API to make web applications communicate with each other regardless of the underlying platform.
Divide Individual Transactions into Small Modules
A REST API divides each transaction into a number of modules. Each module handles a specific aspect of the transaction. The modules make it easier for developers to make web applications interact with other applications and systems in a flexible way. The developer can even boost the performance of web applications by chaining the requests and collecting the requests for future use.
Work with Cloud Platforms and Applications
The REST API makes it easier for developers to make web applications interact with various cloud-based applications. The developers can avail the REST APIs provided by major cloud service providers to leverage key benefits of cloud services including lower cost and enhanced scalability. They can even use stateless components to scale the cloud resources according to varying user load of the website. The web developers can even use the APIs to work with widely used cloud computing models like Infrastructure as a Service (IaaS).
Choose from Many REST APIs
The web developers can easily make the web applications interactive using REST APIs provided by major tech companies like Google, Microsoft, Amazon, and popular social networking platforms. They even have option to choose from a wide range of third-party REST APIs according to precise communication needs of the web applications. At present, web developers use a variety of REST APIs – Google Translation REST API, Facebook REST API, WordPress REST API, Magento REST API, and Bing Maps REST API.
Create Your Own REST API
In addition to using a number of third-party REST APIs, the web developers even have option to create custom REST APIs to meet their precise needs. They can create custom REST APIs based on the six key constraints of REST technology – client-server, stateless, cacheable, uniform interface, layered system, and code on demand. Also, they can implement a number of best practices and use robust tools to accelerate development of custom REST APIs. Here is a brief guide to building restful APIs with Laravel.

On the whole, the web developers can use REST APIs to make web applications interact seamlessly with applications written in different programming languages and running on varying platforms. They also have option to choose from a wide range of third-party REST APIs provided by social networking platforms, search engines, content management systems, and cloud service providers. At the same time, the web developers can even create custom REST APIs based according to their precise needs.