What is the difference between PUT, POST and PATCH?

Here are the main differences everyone should know with your Http Verbs.

HTTP POST

Should be used when sending data to the server for newly created resources.

Example:-

POST /test/create HTTP/1.1
Host: jonbock.com
name1=value1&name2=value2

Response:-

  • 201 (Created)
  • 200 Ok
  • 204 No Content

Ensure that POST

  • Are not cached on the client or server side, each call will result in a attempt to create the resource
  • Requests have no restrictions on data length

 

 

HTTP PUT

HTTP PUTs should be idempotent when used to create/update a resource, this means that each call should result in the same result occurring. The main difference between PUT and POST is that POST could result in side effects when called multiple times.

Example:-

Response:-

  • 201 (Created)
  • 200 Ok
  • 204 No content

 

HTTP PATCH

HTTP PATCH is used to update partial entity, it is usually used to send one or more changes to the server to be applied.

Example:-

HTTP PATCH /users/1

[
     { “op”: “replace”, “path”: “/email”, “value”: “[email protected]” }
]

Response:-

  • 204 No content

 

[Code Smell] Primitive obsession

One of the most important aspects in refactoring the most effective way is looking out for Primitive obsession.

What is it?

  • The usage of primitive types instead of utilising small objects to represent data.
  • Use of constants for the setting of information such as role=1
  • Overuse of primitive types can make extending functionality more complicated and introduce more tech debt.

 

Why is this a problem?

Primitive obsession can come about from programming laziness and short cutting. If I want to store a title of a book in my class, then why not just use a string? Its much easier than creating a new object?

As you add more properties to the class, then things start to introduce more noise and the class become larger and harder to read.

 

How to treat this smell?

With lots of primitive types being introduced to the class one way to try and resolve this is to try to group them into logical groups in their own class. Examples of grouping can be something like functionality, behaviour or domain.

Code will become more flexible than using lots of primitive types, and creates a better understanding and organisation of code. It also makes it easier to find duplicated code when they are grouped into the same area of the code base.

Tiered Compilation with .Net Core 2.1

With all the interesting improvements that the team at Microsoft are undertaking relating to performance improvements, I would like to highlight a new preview release that they have provided for new performance enhancements.

Here is just a overview summary of what they have talked about, you can read more in their main article below.

Compilation with .Net Framework

  • Historically compilation performed with tradeoffs, with combination of PreJitting to optimize code for steady state performance, but is slow and will affect initial start time.
  • Alternative method like an econoJit approach that will start fast but code quality will suffer.
  • .Net provides a combination in order to take a balanced approach that will provide a reasonable job for both start up and steady state peformance.

Tiered performance allows .Net to have multiple compilations so that they can be hot swapped, so we can pick best technique for startup and best for steady state performance.

the benefits of this are:-

  • Faster application startup time
    • Tiered compilation ask JIT to compile quickly and optimise if needed.
  • Faster steady state performance
    • Tiered compilation ask JIT to create optimised code in background thread that will replace the pre compiled version.

 

To try this:-

  • If you build the application yourself using .NET 2.1 SDK – Add the MSBuild property <TieredCompilation>true</TieredCompilation>to the default property group in your project file. For example:
<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
      <OutputType>Exe</OutputType>
      <TargetFramework>netcoreapp2.1</TargetFramework>
      <TieredCompilation>true</TieredCompilation>
    </PropertyGroup>
</Project>
  • If you run an application that has already been built, edit runtimeconfig.json to add System.Runtime.TieredCompilation=true to the configProperties. For example:
  {
      "runtimeOptions": {
        "configProperties": {
          "System.Runtime.TieredCompilation": true
        }
      },
      "framework": {
        ...
      }
    }
  • If you run an application and don’t want to modify any files, set the environment variable
COMPlus_TieredCompilation=1

 

Reference: https://blogs.msdn.microsoft.com/dotnet/2018/08/02/tiered-compilation-preview-in-net-core-2-1/