What is Midrash?
The Midrash (plural - Midrashim) is the method by which ancient Rabbi investigated (Midrash means "to investigate"..from the root darash) Scripture in order to derive laws and teachings not apparent in the p'shat (literal) reading.
This searching of Scripture is traced back to Ezra:
Ezra 7:10 For Ezra had set his heart to expound (drash) the Torah of Hashem and to do fulfill and to teach [its] statute and law in Yisra'el.
There are two categories of the Midrashim - Aggadic Midrashim and Halakhic Midrashim (or Tannaitic Midrashim).
Halakhic Midrashim - the Tannaim use the Midrashic method to derive laws (Halakhot) from Scriptural passages....every Scriptural phrase, word, and even letter is significant.
Aggadic Midrashim is a form of teaching that seeks to admonish and edify: "If you wish to know the Creator of the world, learn Haggadah; from it you will come to know G-d and cling to His ways" (Sifre Devarim 49). The historical themes of the Scriptures are midrashically interpreted in such a way that the entire story of Yisrael becomes a continuous revelation of G-d's love and justice.
Examples of the two:
A Halachic Midrash, seeking to discover the law that the Shabbat can be profaned in order to save life (e.g. where the doctors say that hot food must be served to a dangerously sick person and no hot food is available...so one is allowed to cook) derives this from the verse: "You shall keep My decrees and My laws, which man shall carry out and by which he shall live - I am Hashem" (VaYikra 18:5) Since the verse states "shall live", it is implied that where death may result from the observance of the laws, the laws may be set aside.
A Aggadic Midrash is the comment on the verse: "...G-d did not lead them by way of the land of the Pelishtim,..." (Shemot 13:17), that is, His providence over the Yisralim in the Wilderness was not through natural process ('the way of the land"). In natural order bread comes from the ground and water from the sky, whereas in the Wilderness the Manna came from heaven and water from the flinty rock.
There are three main Halachic Midrashim:
The Jewish Religion - Jacobs