Creating an API [Question]

IG Professor

BANNED
Joined
Feb 22, 2017
Messages
4,855
Reaction score
4,567
I am looking to build an API that will fire random strings from the list that I will insert to it each time when someone use request command. I am total newbie in this field and my question is, How complicated it is to build something like that? or it isn't complicated at all? thanks
 
Okay, let me try to understand. You have a list of random strings in a csv file or whatever. Someone uses the "Request" API and will get a random string from the file? This should be fairly easy. Couple hours if you know how to fire up a server and write back-end code.
 
Okay, let me try to understand. You have a list of random strings in a csv file or whatever. Someone uses the "Request" API and will get a random string from the file? This should be fairly easy. Couple hours if you know how to fire up a server and write back-end code.

Let me tell you exactly, I am creating a chat bot. now when person X will click on it - it will fire random string from a list that I have.
In the chatbot software, I have an option to add JSON file from URL.
So from what I understand, I need to code JSON file that will fire 1 random string each time that a client click on 'NOW' in the chatbot

I have no clue about coding. However: I can create the JSON file. just need the code. Where should I start?
Thanks for your support
 
It's hard to say where to start or how to exactly do it without understanding what chatbot software you have set up currently. I.e what language it's written in, what server, etc... I suggest you post a section in hire a freelancer and post specific details to your task.

Sorry if I wasn't helpful. I mean I understand the general concept but without details it'll be hard to do.
 
Maybe we can working together? can I have your Telegram please?
 
So basically you want the api to return a random string that it will get from a .txt file or something?
That's very simple, I can give you a php/python code if you want
 
So basically you want the api to return a random string that it will get from a .txt file or something?
That's very simple, I can give you a php/python code if you want
Yeah man. exactly what you are saying.
This is what I was thinking : Hiring someone to create the code for me - I will send him the random strings that I want it to send each time when client make a request. (Random string for each different client)
After I have the code, I will use this website: http://www.json-generator.com and paste it on there to convert the code to json file. What do you think?
 
Code:
import random
from flask import Flask, jsonify

app = Flask(__name__)

@app.route('/ranstr')
def ranstr():
    foo = ['hope', 'this', 'will', 'help', 'you']
    sec_ran = random.SystemRandom()
    return jsonify({'stat': True, 'msg': sec_ran.choice(foo)})

if __name__ == '__main__':
    app.run()
demo :
Code:
amiu(dot)org/ranstr
that flask code, generate random string from list..
if you want generate unique string for each user, you must use database..
try heroku + mlab for trial and error..

nb: I'm not good in php..
 
Code:
import random
from flask import Flask, jsonify

app = Flask(__name__)

@app.route('/ranstr')
def ranstr():
    foo = ['hope', 'this', 'will', 'help', 'you']
    sec_ran = random.SystemRandom()
    return jsonify({'stat': True, 'msg': sec_ran.choice(foo)})

if __name__ == '__main__':
    app.run()
demo :
Code:
amiu(dot)org/ranstr
that flask code, generate random string from list..
if you want generate unique string for each user, you must use database..
try heroku + mlab for trial and error..

nb: I'm not good in php..

foo = ['hope', 'this', 'will', 'help', 'you']


Should I change the words to my strings, paste the code and that's it?
 
foo = ['hope', 'this', 'will', 'help', 'you']
Should I change the words to my strings, paste the code and that's it?
yes right.. but good solution is use database..
so you can easy add new data or remove instead re-push code each time you want update your list..
also you can make unique value for each user..
 
yes right.. but good solution is use database..
so you can easy add new data or remove instead re-push code each time you want update your list..
also you can make unique value for each user..

Thank you so much. I am appreciate it.
 
Have a look at loopback on node.js, creates a standards compliant REST api for you. It's a pain to set up initially compared to a simple php script, but you'll be thankful when you want to extend it. It will also add ability to add new strings via the API and support authentication etc. Works with a mysql/mongodb database.
 
Yeah man. exactly what you are saying.
This is what I was thinking : Hiring someone to create the code for me - I will send him the random strings that I want it to send each time when client make a request. (Random string for each different client)
After I have the code, I will use this website: www.json-generator.com and paste it on there to convert the code to json file. What do you think?
You don't really need to use that website, the code can return the result in json format. If you have a webhosting, I can send you a PHP code that will do the job
 
This is easy peasy done in 10 minutes in PHP if you just read from a text file.
Shared hosting is more than enough if there's not much load.
 
An API requires routes with functions that do query to database.
I recommend using NoSQL for something simple, maybe MongoDB.
NodeJS is really nice for quick API's using ExpressJS. Define your routes, do your queries and return data on the API.

Then with that data you can consume with anything, you can consume from a compiled app or a web app. This is helpful cause you separate the core backend and the frontend.
 
I think the hard thing about this is to react to the chat messages and send the replies. Retrieving the replies from a file or database is the simple thing about this.
 
Back
Top