Create Simple Api for a Blog

Hi all,

I’m very new to this Slim framework and REST API but i would like to learn it, so i started create an simple API for blog with MYSQL but i got stuck, can someone help me explain how could i send the blog post content ( long texts , many characters ) via JSON, what is a better way ?
Any help will be apreciated.

Thanks,

Hello @LeoVinci

Slim is super nice to build fast and solid api’s, so it’s a good way into rest api’s.
If you could elaborate more on what your issue is.

So the most typical way to use a rest api is to build these endpoints like get post put delete for each resources.

Let’s say you have an endpoint that serves posts then you have an endpoint called /api/v1/posts this “should” serve all your post from some giving criterias.
then for a specific resource you can make an endpoint called /api/v1/posts/{id} then you can get a specific post.

So in your usecase the api’s task is to serve some information to the client the client could be EG (frontend application)

Regarding sending blog post content this will happen through via a post request. Then you will make the client be able to send a json payload and then in your post request you will make functionallity that either insert into a database or store that information in some sense.

I know this is very general but I hope it helps a little.

1 Like

Thank you so much @ tobiasbm
Very clearly, but is there any better way to send long texts via JSON ?
Let’s say i have an API call from client to get content of a Post . Ex : /api/v1/post/{id}
After received that request, i find post detail from database, then send a response to client. Should be like: {‘title’ : ‘abc’, content: ‘very very long texts here…’}
I mean is there any problem if i send long texts like that via API ? is there a better way to do that ?

Hi, Its not an issue. But what you can do is on your list view of articles you can truncate that long text as a blurb and then when the user open the article send the whole text.