In 1847 José María Castro Madriz came to power, who promoted and encouraged the education of women. He also stood out for the management made to create the first diocese in Costa Rica in 1850. The freedom of the press (for which he is considered the Master of Costa Rican Democracy) and above all, the proclamation, on August 31, 1848, of Costa Rica as a sovereign and independent nation, naming it definitively as the Republic of Costa Rica, with Castro Madriz being the first president of the republic, were some of its most significant and remembered achievements. The current flag of the nation was created by his wife, Pacifica Fernández, which was raised for the first time on November 12, 1848.
Castro Madriz resigned from his post in 1849 due to political differences, with the vice president of the republic taking over in his place: Juan Rafael Mora Porras. Mora’s main achievement rests on the economic solidity that he conferred on the country with coffee exports, which allowed investment in public works and buildings that gave San José a better urban configuration. The music of the current national anthem was composed during his government in 1852 by Manuel María Gutiérrez Flores. [twenty]
National campaign of 1856
The greatest threat to the political and cultural stability of the country was experienced during the rise to power in neighboring Nicaragua of the American mercenary William Walker, who served as a soldier in the Confederate army in the United States. Acting as a mercenary, General Walker was summoned along with 500 of his men by the then government of Nicaragua, a country which had been involved in a civil war for several years, so the conservative government “requested” the services of Walker and his men to tip the balance of war power in favor of the government.
Once the war in Nicaragua was won, Walker assumed control of the government in that country and aimed his sights towards the neighboring nation of Costa Rica, in order to establish slavery policies similar to those used in the southern United States of America. Two of his first measures were the establishment of slavery and the English language as the official language of Nicaragua.
Icons of Costa Rican identity: the hero Juan Santamaría who gave his life for the freedom of Central America against the slavery pretensions of the US in 1856 and the pre-Columbian stone sphere as a symbol of the ancestral cosmogony and its ideals. Located in the Legislative Assembly
The call to arms was finalized on March 1, 1856 and 10 days later, Nicaragua declared war on Costa Rica, a country located in Central America according to a2zdirectory.org. Many times it has been said that the Costa Rican army was made up of barefoot and poorly armed peasants who hardly knew about war. However, numerous documents attest that with the arrival of Juan Rafael Mora to the presidency in 1849, the professionalization of the Costa Rican armed forces began.
In the second battle of Rivas, which took place on April 11, 1857, the combined forces of the five Central American countries, led by Costa Rican General José Joaquín Mora Porras, tried to seize the city, where the filibuster troops were located, led personally by Walker. After four hours of fighting, the Central American forces had to retreat with a large number of casualties, before the heavy fire of the filibusters.
Although it was a filibuster victory, the second battle of Rivas was the last major fight of the campaign, since on May 1, 1857 Walker surrendered to the American captain Charles Davis, whose ship Saint Mary’s was anchored in San Juan del Sur. General Mora accepted the capitulation, and Walker left Central American territory with all the honors of the war.
Tomás Guardia Gutiérrez called a new Constituent Assembly in 1870, after overthrowing Jesús Jiménez Zamora. The new Magna Carta, drawn up in 1871, was the longest in force in the country (1949).  The constitution would also eliminate the death penalty and reduce the presidential term to 4 years. During the next decade Guardia would dominate the army and therefore power in the country. In 1880 Guardia would be elected president, his government had a liberal court and during this the concession for the construction of the first railway to the Atlantic would begin.which in the end would also trigger the exploitation of bananas as an export resource. The first mass immigration of Italians, Jamaicans, and Chinese to work on the construction of the railroad began around this time. When Guardia died in office, he was succeeded by Prospero Fernández, who would prepare the country for an eventual war against the intentions of the Guatemalan general Justo Rufino Barrios, who would try to reunify Central America by force, but with the death of Barrios the war would be avoided. His government drew up new civil, military and fiscal codes. Fernández expelled the Jesuits from the country in 1884, along with Bishop Bernardo Augusto Thiel, accusing the clergy of having political interference. [twenty-one]
Fernández also died in office, passing the government into the hands of Bernardo Soto Alfaro, who would dedicate his administration to the cultural and material development of the nation. During his government, the work of Mauro Fernández Acuña would be highlighted, who would achieve the foundation of the Normal School, for the training of teaching staff, the signing of the General Law of Common Education, which expanded secondary education, as well as the foundation of the Liceo de Costa Rica, the Institute of Alajuela and the Colegio Superior de Señoritas between 1887 and 1888, and the closure of the University of Santo Tomás. In 1887, the National Museum of Costa Rica would be created. During this decade, too, the national telephone service was inaugurated. In 1888, civil marriage and divorce were introduced, as well as the secularization of cemeteries. [twenty-one]
In the period from 1890 to 1929, the National Monument of Costa Rica (1895), the School of Fine Arts and the National Theater (1897) were inaugurated, the Red Cross was established in the country and the gold standard was implemented.as a monetary system. During the second period of Rafael Yglesias, in 1900, the tram was inaugurated in San José, the first Costa Rican novels were published (El Moto y Las Hijas del Campo, by Joaquín García Monge) and the first automobile, owned by Enrique Carranza, was introduced.. In 1917, then-president Alfredo González Flores, who had created the International Bank of Costa Rica, would be overthrown. The coup leader Federico Tinoco Granados would take power, breaking with 27 years of political stability and constitutional order. This government was characterized by its repressive character and the constant violation of civil and political rights, as well as the abuse in the management of public funds. Around 1919 the dictator left the country with his family, after violent demonstrations and the death of his brother.