The aim of this diploma thesis was to summarize all necessary knowledge needed for preparation of a quality CaP coating on AZ31 wrought magnesium alloys, and to implement its optimization for use in simulated body fluids. The theoretical part discusses biomaterials and their classification. Subsequently, the potential of magnesium alloys, their corrosion, and the possibility of surface treatment for in vivo applications are described in detail. The theoretical part concludes with the mechanism of deposition of CaP coatings on magnesium alloys and methods to evaluate their corrosion resistance. The experimental part includes the process of optimization of Mg alloy pretreatment and optimization of CaP coatings preparation, where the quality evaluation criteria were the appearance of the coating and its electrochemical and corrosion properties. These were evaluated by potentiodynamic tests. The microstructure and the chemical composition of deposited coating were observed and measured by optical and scanning electron microscopy. Long-term corrosion tests using electrochemical impedance spectroscopy (EIS) were performed on the optimized CaP coatings and these results were then compared with the corrosion properties of the uncoated AZ31 alloy.