I’ve read a lot of fantasy stories, some of them are good, and some are are awful. The thing I’ve noticed about the good fantasy stories is the care an author takes when they build magic into the narrative.
It is far too easy when you have magic in a story to use it as a crutch - a get out of jail free card for when you’ve written your characters into an inescapable corner. This can be the definitive Deus Ex Machina answer to any problem. Character on the verge of death? Fix it with magic. World is about to implode and kill every living thing? Just say abracadabra and wave a wand. That is when fantasy stories start to go wrong.
The best approach is to consider magic as a form of physics. For a writer to lay out what things magic can do in their story, and perhaps more importantly, what it cannot do. Magic with rules is far more believable than unlimited magic.
To offer some examples, I’ll begin with the Harry Potter universe. It is filled with magic, it being the very essence of the story, however, JK Rowling was careful to build in rules. Spells that only last for a limited time. Potions with side effects. There are many spells that help the characters out of certain situations, but they are specific and have various other uses rather than one-time band aids.
To pull from a classic, consider Tolkien’s Middle Earth. Gandalf and his buddy wizards use magic, but their strength is limited, even Sauron's magic is restricted - I guess being stuck as an eye at the top of a tower will do that to a guy. In Terry Pratchett’s Discworld, magic is more often the cause of trouble than it is the solution.
The history of magic in folklore is fascinating for anyone who wishes to look into it. There is a wealth of ideas around, some more known than others.
When it comes to writing a story that contains magic it is important for the writer to focus on the system they wish to use. Who can use magic? Is it just a certain set of characters or is it open to everyone in your world? How is magic obtained? Is it naturally occurring, a sort of inherent magic gene, or must someone study and learn it, or even obtain it through some foreign object (finding a hidden chalice or magical orb or similar). The rules are paramount. You need to decide if magic can affect the physical (making objects fly or change shape) or mental (mindreading) and stick to your own rules.
When I chose to include a magical element in the steampunk series, I sat down and wrote out some basic structures. There are two kinds of magic in the world, one is caused by ingestion or injection of Anthonium, a rare element. The element is actually a poison and if taken in too large a dose it will kill someone, but just the right dose and a person gets some unique physical abilities, such as enhanced healing, becoming impervious to heat, or invisibility (only one ability per person). The other magical component comes from priests studying a specific branch of the religion of my world. They can obtain the skill to build illusion objects, such as an orb that can change the physical appearance of something. Very skilled priests can perform a sort of mind-link to another person. These elements, while important to the story, are very limited in their nature. I didn’t want to have magic devices all over the place giving the characters easy answers to the problems that come up.
Taking time to build the structure for magic in your world is how you make magic appear “real”, and more believable.