# Effortlessly Convert Markdown to HTML with GitHub API - A Developer's Guide

By Dinesh Uprety
Published: 2024-05-17
Updated: 2024-05-17
Canonical: https://laranepal.com/blog/effortlessly-convert-markdown-to-html-with-github-api-a-developers-guide

# Tips for Using GitHub API to Convert Markdown to HTML

Hey **PHP Developer**, I'm here to guide you on how to convert Markdown to HTML using the GitHub API in a Laravel application. Follow these steps and tips to ensure a secure, efficient, and scalable solution for your Markdown conversion needs. Replace `withToken('<YOUR-TOKEN>')` with your GitHub API token. Be aware of GitHub API rate limits, especially if you plan to convert a large number of Markdown documents. Consider using **Cache** to handle rate limits effectively.


```php
<?php

use Illuminate\Support\Facades\Http;

public function convert()
{
        $markdown = json_encode([
            'text' => 'Hello **world** ```php <?php echo "hello"; ?> ```',
        ]);

       $response =  Http::withBody($markdown)
            ->withToken('<YOUR-TOKEN>')
            ->withHeaders([
                'Accept' => 'application/vnd.github+json',
                'X-GitHub-Api-Version' => '2022-11-28',
            ])
            ->post('https://api.github.com/markdown');

        if($response->failed())
        {
            return $this->error("Something went wrong");
        }

        dd($response->body());
}
```
### Output
```sh
"<p>Hello <strong>world</strong> <code>php &lt;?php echo "hello"; ?&gt; </code></p>\n"
```

By following these tips, you can efficiently convert Markdown to HTML using the [GitHub API](https://docs.github.com/en/rest/markdown/markdown?apiVersion=2022-11-28) in your Laravel application.

