<s>
In	O
computing	O
,	O
the	O
PATCH	B-Protocol
method	O
is	O
a	O
request	B-Protocol
method	O
in	O
HTTP	B-Protocol
for	O
making	O
partial	O
changes	O
to	O
an	O
existing	O
resource	O
.	O
</s>
<s>
The	O
PATCH	B-Protocol
method	O
provides	O
an	O
entity	O
containing	O
a	O
list	O
of	O
changes	O
to	O
be	O
applied	O
to	O
the	O
resource	O
requested	O
using	O
the	O
HTTP	B-Protocol
Uniform	B-Protocol
Resource	I-Protocol
Identifier	I-Protocol
(	O
URI	B-Protocol
)	O
.	O
</s>
<s>
The	O
list	O
of	O
changes	O
are	O
supplied	O
in	O
the	O
form	O
of	O
a	O
PATCH	B-Protocol
document	O
.	O
</s>
<s>
If	O
the	O
requested	O
resource	O
does	O
not	O
exist	O
then	O
the	O
server	B-Application
may	O
create	O
the	O
resource	O
depending	O
on	O
the	O
PATCH	B-Protocol
document	O
media	B-Application
type	I-Application
and	O
permissions	O
.	O
</s>
<s>
The	O
changes	O
described	O
in	O
the	O
PATCH	B-Protocol
document	O
must	O
be	O
semantically	O
well	O
defined	O
but	O
can	O
have	O
a	O
different	O
media	B-Application
type	I-Application
than	O
the	O
resource	O
being	O
patched	O
.	O
</s>
<s>
Languages	O
such	O
as	O
XML	B-Protocol
or	O
JSON	B-General_Concept
can	O
be	O
used	O
in	O
describing	O
the	O
changes	O
in	O
the	O
PATCH	B-Protocol
document	O
.	O
</s>
<s>
As	O
per	O
the	O
semantics	O
defined	O
in	O
the	O
HTTP	B-Protocol
protocol	I-Protocol
,	O
the	O
GET	O
,	O
PUT	O
,	O
and	O
POST	B-Protocol
methods	O
need	O
to	O
use	O
a	O
full	O
representation	O
of	O
the	O
resource	O
.	O
</s>
<s>
The	O
edit	O
forms	O
used	O
in	O
conventional	O
Ruby	B-Application
on	I-Application
Rails	I-Application
application	O
need	O
to	O
create	O
new	O
resources	O
by	O
applying	O
partial	O
updates	O
to	O
a	O
parent	O
resource	O
.	O
</s>
<s>
Due	O
to	O
this	O
requirement	O
,	O
the	O
PATCH	B-Protocol
method	O
was	O
added	O
to	O
the	O
HTTP	B-Protocol
protocol	I-Protocol
in	O
2010	O
.	O
</s>
<s>
HTTP	B-Protocol
is	O
the	O
foundation	O
of	O
data	O
communication	O
for	O
the	O
World	O
Wide	O
Web	O
.	O
</s>
<s>
It	O
is	O
a	O
request-response	B-Protocol
protocol	O
which	O
helps	O
users	O
communicate	O
with	O
the	O
server	B-Application
to	O
perform	O
CRUD	B-General_Concept
operations	O
.	O
</s>
<s>
HTTP	B-Protocol
defines	O
a	O
number	O
of	O
request	B-Protocol
methods	O
such	O
as	O
PUT	O
,	O
POST	B-Protocol
and	O
PATCH	B-Protocol
to	O
create	O
or	O
update	O
resources	O
.	O
</s>
<s>
The	O
main	O
difference	O
between	O
the	O
PUT	O
and	O
PATCH	B-Protocol
method	O
is	O
that	O
the	O
PUT	O
method	O
uses	O
the	O
request	B-Protocol
URI	B-Protocol
to	O
supply	O
a	O
modified	O
version	O
of	O
the	O
requested	O
resource	O
which	O
replaces	O
the	O
original	O
version	O
of	O
the	O
resource	O
,	O
whereas	O
the	O
PATCH	B-Protocol
method	O
supplies	O
a	O
set	O
of	O
instructions	O
to	O
modify	O
the	O
resource	O
.	O
</s>
<s>
If	O
the	O
PATCH	B-Protocol
document	O
is	O
larger	O
than	O
the	O
size	O
of	O
the	O
new	O
version	O
of	O
the	O
resource	O
sent	O
by	O
the	O
method	O
then	O
the	O
method	O
is	O
preferred	O
.	O
</s>
<s>
The	O
POST	B-Protocol
method	O
can	O
be	O
used	O
for	O
sending	O
partial	O
updates	O
to	O
a	O
resource	O
.	O
</s>
<s>
The	O
main	O
difference	O
between	O
the	O
POST	B-Protocol
and	O
PATCH	B-Protocol
methods	O
is	O
that	O
the	O
POST	B-Protocol
method	O
can	O
be	O
used	O
only	O
when	O
it	O
is	O
written	O
to	O
support	O
the	O
applications	O
or	O
the	O
applications	O
support	O
its	O
semantics	O
whereas	O
the	O
PATCH	B-Protocol
method	O
can	O
be	O
used	O
in	O
a	O
generic	O
way	O
and	O
does	O
not	O
require	O
application	O
support	O
.	O
</s>
<s>
If	O
the	O
outcome	O
of	O
using	O
the	O
PATCH	B-Protocol
method	O
is	O
not	O
known	O
then	O
the	O
POST	B-Protocol
method	O
is	O
preferred	O
.	O
</s>
<s>
The	O
PATCH	B-Protocol
method	O
is	O
atomic	B-General_Concept
.	O
</s>
<s>
Either	O
all	O
the	O
changes	O
specified	O
by	O
the	O
PATCH	B-Protocol
method	O
are	O
applied	O
or	O
none	O
of	O
the	O
changes	O
are	O
applied	O
by	O
the	O
server	B-Application
.	O
</s>
<s>
There	O
are	O
many	O
ways	O
of	O
checking	O
whether	O
a	O
patch	B-Protocol
was	O
applied	O
successfully	O
.	O
</s>
<s>
For	O
example	O
,	O
the	O
'	B-Application
diff	I-Application
 '	I-Application
utility	I-Application
can	O
be	O
applied	O
to	O
the	O
older	O
version	O
and	O
newer	O
version	O
of	O
a	O
file	O
to	O
find	O
the	O
differences	O
between	O
them	O
.	O
</s>
<s>
A	O
cached	O
PATCH	B-Protocol
response	O
is	O
considered	O
stale	O
.	O
</s>
<s>
It	O
can	O
only	O
be	O
used	O
for	O
the	O
GET	O
and	O
HEAD	O
requests	O
that	O
may	O
follow	O
the	O
PATCH	B-Protocol
request	B-Protocol
.	O
</s>
<s>
The	O
entity	O
headers	O
in	O
the	O
PATCH	B-Protocol
document	O
are	O
only	O
applicable	O
to	O
the	O
PATCH	B-Protocol
document	O
and	O
cannot	O
be	O
applied	O
to	O
the	O
requested	O
resource	O
.	O
</s>
<s>
There	O
is	O
no	O
standard	O
format	O
for	O
the	O
PATCH	B-Protocol
document	O
and	O
it	O
is	O
different	O
for	O
different	O
types	O
of	O
resources	O
.	O
</s>
<s>
The	O
server	B-Application
has	O
to	O
check	O
whether	O
the	O
PATCH	B-Protocol
document	O
received	O
is	O
appropriate	O
for	O
the	O
requested	O
resource	O
.	O
</s>
<s>
Before	O
applying	O
the	O
changes	O
in	O
the	O
PATCH	B-Protocol
document	O
,	O
the	O
server	B-Application
has	O
to	O
check	O
whether	O
the	O
PATCH	B-Protocol
document	O
received	O
is	O
appropriate	O
for	O
the	O
requested	O
resource	O
.	O
</s>
<s>
If	O
the	O
PATCH	B-Protocol
request	B-Protocol
succeeds	O
then	O
it	O
returns	O
a	O
204	O
response	O
.	O
</s>
<s>
Successful	O
PATCH	B-Protocol
response	O
to	O
existing	O
text	O
file	O
:	O
</s>
<s>
The	O
response	O
204	O
means	O
that	O
the	O
request	B-Protocol
was	O
processed	O
successfully	O
.	O
</s>
<s>
Using	O
the	O
PUT	O
method	O
consumes	O
more	O
bandwidth	O
as	O
compared	O
to	O
the	O
PATCH	B-Protocol
method	O
when	O
only	O
a	O
few	O
changes	O
need	O
to	O
be	O
applied	O
to	O
a	O
resource	O
.	O
</s>
<s>
But	O
when	O
the	O
PATCH	B-Protocol
method	O
is	O
used	O
,	O
it	O
usually	O
involves	O
fetching	O
the	O
resource	O
from	O
the	O
server	B-Application
,	O
comparing	O
the	O
original	O
and	O
new	O
files	O
,	O
creating	O
and	O
sending	O
a	O
diff	B-Application
file	O
.	O
</s>
<s>
On	O
the	O
server	B-Application
side	O
,	O
the	O
server	B-Application
has	O
to	O
read	O
the	O
diff	B-Application
file	O
and	O
make	O
the	O
modifications	O
.	O
</s>
<s>
The	O
PATCH	B-Protocol
method	O
is	O
not	O
"	O
safe	O
"	O
in	O
the	O
sense	O
of	O
RFC	B-Protocol
2616	I-Protocol
:	O
it	O
may	O
modify	O
resources	O
,	O
not	O
necessarily	O
limited	O
to	O
those	O
mentioned	O
in	O
the	O
URI	B-Protocol
.	O
</s>
<s>
The	O
PATCH	B-Protocol
method	O
is	O
not	O
idempotent	O
.	O
</s>
<s>
It	O
can	O
be	O
made	O
idempotent	O
by	O
using	O
a	O
conditional	O
request	B-Protocol
.	O
</s>
<s>
When	O
a	O
client	O
makes	O
a	O
conditional	O
request	B-Protocol
to	O
a	O
resource	O
,	O
the	O
request	B-Protocol
succeeds	O
only	O
if	O
the	O
resource	O
has	O
not	O
been	O
updated	O
since	O
the	O
client	O
last	O
accessed	O
that	O
resource	O
.	O
</s>
<s>
A	O
PATCH	B-Protocol
request	B-Protocol
can	O
fail	O
if	O
any	O
of	O
the	O
following	O
errors	O
occur	O
:	O
</s>
<s>
The	O
server	B-Application
returns	O
a	O
400	O
(	O
Bad	O
request	B-Protocol
)	O
response	O
if	O
the	O
PATCH	B-Protocol
document	O
is	O
not	O
formatted	O
as	O
required	O
.	O
</s>
<s>
The	O
server	B-Application
returns	O
a	O
415	O
(	O
Unsupported	O
Media	B-Application
Type	I-Application
)	O
response	O
with	O
an	O
Accept-Patch	B-Protocol
response	I-Protocol
header	I-Protocol
containing	O
supported	O
media	B-Application
types	I-Application
when	O
the	O
client	O
sends	O
a	O
patch	B-Protocol
document	O
in	O
a	O
format	O
not	O
implemented	O
by	O
the	O
server	B-Application
.	O
</s>
<s>
This	O
informs	O
the	O
client	O
that	O
the	O
PATCH	B-Protocol
document	O
sent	O
by	O
the	O
client	O
cannot	O
be	O
applied	O
to	O
the	O
requested	O
resource	O
.	O
</s>
<s>
The	O
server	B-Application
returns	O
a	O
422	O
(	O
Unprocessable	O
Entity	O
)	O
response	O
when	O
the	O
server	B-Application
understands	O
the	O
PATCH	B-Protocol
document	O
but	O
is	O
unable	O
to	O
modify	O
the	O
requested	O
resource	O
either	O
because	O
it	O
causes	O
the	O
resource	O
to	O
become	O
invalid	O
or	O
it	O
results	O
in	O
some	O
other	O
error	O
state	O
.	O
</s>
<s>
The	O
server	B-Application
returns	O
a	O
404	O
(	O
Not	O
Found	O
)	O
response	O
when	O
the	O
PATCH	B-Protocol
document	O
cannot	O
be	O
applied	O
to	O
a	O
non-existent	O
resource	O
.	O
</s>
<s>
The	O
server	B-Application
returns	O
a	O
409	O
(	O
Conflict	O
)	O
response	O
when	O
the	O
server	B-Application
cannot	O
apply	O
a	O
patch	B-Protocol
for	O
the	O
current	O
state	O
of	O
the	O
resource	O
.	O
</s>
<s>
The	O
server	B-Application
returns	O
a	O
412	O
(	O
Precondition	O
Failed	O
)	O
response	O
when	O
the	O
precondition	O
supplied	O
by	O
the	O
client	O
using	O
the	O
or	O
If-Unmodified-Since	O
header	O
fails	O
.	O
</s>
<s>
If	O
no	O
precondition	O
is	O
supplied	O
and	O
there	O
is	O
a	O
conflicting	O
modification	O
then	O
the	O
server	B-Application
returns	O
a	O
409	O
(	O
Conflict	O
)	O
response	O
.	O
</s>
<s>
The	O
server	B-Application
returns	O
a	O
409	O
(	O
Conflict	O
)	O
response	O
if	O
the	O
PATCH	B-Protocol
requests	O
to	O
a	O
certain	O
resource	O
need	O
to	O
be	O
applied	O
in	O
a	O
certain	O
order	O
and	O
the	O
server	B-Application
is	O
not	O
able	O
to	O
handle	O
concurrent	O
PATCH	B-Protocol
requests	O
.	O
</s>
<s>
The	O
PATCH	B-Protocol
request	B-Protocol
needs	O
to	O
use	O
mechanisms	O
such	O
as	O
conditional	O
requests	O
using	O
Etags	B-Protocol
and	O
the	O
request	B-Protocol
header	O
to	O
ensure	O
that	O
data	O
is	O
not	O
corrupted	O
while	O
patching	O
.	O
</s>
<s>
In	O
case	O
of	O
a	O
failure	O
of	O
a	O
PATCH	B-Protocol
request	B-Protocol
or	O
failure	O
of	O
the	O
channel	O
or	O
a	O
timeout	O
,	O
the	O
client	O
can	O
use	O
a	O
request	B-Protocol
to	O
check	O
the	O
state	O
of	O
the	O
resource	O
.	O
</s>
<s>
The	O
server	B-Application
has	O
to	O
ensure	O
that	O
malicious	O
clients	O
do	O
not	O
use	O
the	O
PATCH	B-Protocol
method	O
for	O
consuming	O
excessive	O
server	B-Application
resources	O
.	O
</s>
