Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,519 members, 7,808,895 topics. Date: Thursday, 25 April 2024 at 06:54 PM

How Do I Create An API For A Website Or Blog In JSON Format. - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / How Do I Create An API For A Website Or Blog In JSON Format. (1398 Views)

List Of All States With Local Governments In Nigeria In JSON, PHP And SQL Format / Mtn Api For Selling Mobile Applications That Is Of Nigerian Origin / Tutorial: How To Return Html In Json Response Using Asp.net And Jquery (2) (3) (4)

(1) (Reply) (Go Down)

How Do I Create An API For A Website Or Blog In JSON Format. by Nobody: 11:05pm On Sep 29, 2014
I need help on how to create an API for a website or Blog that will be outputted as JSON.

Will be grateful if any programmer here can show or direct me to any resource that I can use to achieve this.

I intend to make the API to be accessible to mobile phones.
I also intend doing this on my localhost for now.

Language: PHP MySQL

Thanks?
Re: How Do I Create An API For A Website Or Blog In JSON Format. by jidez007: 11:51pm On Sep 29, 2014
Try laravel php framework, its really easy creating an api with it.
Re: How Do I Create An API For A Website Or Blog In JSON Format. by Nobody: 6:33am On Sep 30, 2014
Okay, thanks, would look at it?
Re: How Do I Create An API For A Website Or Blog In JSON Format. by Nobody: 8:37am On Sep 30, 2014
you can build this up from your mysql_fetch_assoc()
remember to escape html entities when rendering

something like this

$results=array() ; 

while($row = mysql_fetch_assoc($r)){
$results[] = array('subject' => $row['subject'], 'description' => $row['description']) ;
}

$ret= json_encode($results) ;
echo $ret;
Re: How Do I Create An API For A Website Or Blog In JSON Format. by Nobody: 9:02am On Sep 30, 2014
^^^
I actually did this within my MySQL and I tot I could retrieve it inside a WebView in a phone, but it didn't work.

It's saying "no url found"

Thanks.
Re: How Do I Create An API For A Website Or Blog In JSON Format. by spikesC(m): 11:07am On Sep 30, 2014
jidez007: Try laravel php framework, its really easy creating an api with it.

Why framework when he doesn't even know how the basic works
Re: How Do I Create An API For A Website Or Blog In JSON Format. by Nobody: 2:34pm On Sep 30, 2014
spikesC:

Why framework when he doesn't even know how the basic works

I am a newbie in PHP. Maybe you can guide me with any resource that can help.
Re: How Do I Create An API For A Website Or Blog In JSON Format. by Nobody: 2:57pm On Sep 30, 2014
Re: How Do I Create An API For A Website Or Blog In JSON Format. by jidez007: 3:55pm On Sep 30, 2014
spikesC:

Why framework when he doesn't even know how the basic works
I don't tink its compulsory he learns all d basics b4 he can use laravel. E.g using Post::all() will return all d posts in d database as json being d default mode and there are many other easy syntax dat can b used.
Although I won't recommend diving in without knowing d basics of php including oop.
Re: How Do I Create An API For A Website Or Blog In JSON Format. by jidez007: 3:55pm On Sep 30, 2014
Re: How Do I Create An API For A Website Or Blog In JSON Format. by Nobody: 6:26pm On Sep 30, 2014
Djangocode: @op Pls do take a look at this topic
www.brenelz.com/blog/how-to-create-a-simple-api-with-php-and-mysql/


I have looked at that tutorial before and compared it with my own code, both of them have the same flow.

I'm getting my JSON response.
Re: How Do I Create An API For A Website Or Blog In JSON Format. by Nobody: 6:35pm On Sep 30, 2014
Mobile App Developers should understand what I want to do here.
I have never created any API myself before, I just take public API's and use it, but here, I'm forced to create the API myself...
Re: How Do I Create An API For A Website Or Blog In JSON Format. by spikesC(m): 11:15am On Oct 01, 2014
phatjoe50:

I am a newbie in PHP. Maybe you can guide me with any resource that can help.

Search for OReilly RESTful Web Services

I have never read it but coming from Oreilly, it must be good.

Creating an api is basically same thing you've been doing with PHP except of course, the format response you're sending out, being json
Re: How Do I Create An API For A Website Or Blog In JSON Format. by spikesC(m): 11:18am On Oct 01, 2014
jidez007:
I don't tink its compulsory he learns all d basics b4 he can use laravel. E.g using Post::all() will return all d posts in d database as json being d default mode and there are many other easy syntax dat can b used.
Although I won't recommend diving in without knowing d basics of php including oop.

Trust me, it is compulsory he does.
Knowing how to use post::all() without knowing how it does what it does will hurt him in the future.
If he doesn't know the json functions, how else would he be able to really say, "I can work with json objects"
Re: How Do I Create An API For A Website Or Blog In JSON Format. by Nobody: 5:24pm On Oct 01, 2014
spikesC:

Search for OReilly RESTful Web Services

I have never read it but coming from Oreilly, it must be good.

Creating an api is basically same thing you've been doing with PHP except of course, the format response you're sending out, being json

Thanks
Re: How Do I Create An API For A Website Or Blog In JSON Format. by Nobody: 5:37pm On Oct 01, 2014
Thanks guys I have eventually solved the issue, which was just a case of ignorance from me.

I was developing an API for a website and I forgot that every section of a website or blog has a corresponding link or url, which I neglected when developing my API.

Being so naughty I was calling the url which I didn't create in the API from my JAVA with the getString() method passing my url as the key like this getString("url"wink. Absolutely nothing wrong with this only that I didn't create it in my API, LOL. It was after series of debugging today that I got to see the mistake.

My JSON output now look like this.



{
users: [{
"id": "18",
"geTitle": "Gabe's Senior Painting Thesis",
"getDesc": "As a Studio Art major at Wesleyan",
"getAmount": "5600000",
"getDays": "23",
"getArticle": "As a Studio Art major at Wesleyan, I am about to begin work on my senior thesis in painting. !",
"url": "http://localhost/seeds/viewpost.php?id=18",
"time": "2014-10-09"
},


Before the JSON was without the "url" JSONObject.

Thanks for the help. Really Appreciate.
Re: How Do I Create An API For A Website Or Blog In JSON Format. by jidez007: 7:06pm On Oct 01, 2014
phatjoe50: Thanks guys I have eventually solved the issue, which was just a case of ignorance from me.

I was developing an API for a website and I forgot that every section of a website or blog has a corresponding link or url, which I neglected when developing my API.

Being so naughty I was calling the url which I didn't create in the API from my JAVA with the getString() method passing my url as the key like this getString("url"wink. Absolutely nothing wrong with this only that I didn't create it in my API, LOL. It was after series of debugging today that I got to see the mistake.

My JSON output now look like this.

[code]


Before the JSON was without the "url" JSONObject.

Thanks for the help. Really Appreciate.
Becareful so u won't expose a user's password
Re: How Do I Create An API For A Website Or Blog In JSON Format. by Nobody: 7:13pm On Oct 01, 2014
jidez007:
Becareful so u won't expose a user's password

Hahahaha! I know sorry sir.
Re: How Do I Create An API For A Website Or Blog In JSON Format. by Nobody: 7:13pm On Oct 01, 2014
jidez007:
Becareful so u won't expose a user's password
Re: How Do I Create An API For A Website Or Blog In JSON Format. by dhtml(m): 6:39am On Oct 02, 2014
Interesting. . . . .
Re: How Do I Create An API For A Website Or Blog In JSON Format. by Nobody: 6:49am On Oct 02, 2014
dhtml: Interesting. . . . .

^^^
Oga mi I c u jare.

(1) (Reply)

Christian Louboutin Shoes On Sale Extremely / Telegram Bot Challenge / C++ Programming For Beginners

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 24
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.