I am working on an Angular application (using Angular 9) to build out a website that has articles written by my organization. I would be publishing the articles on my own time after reviewing their emailed submissions to me. I am thinking of using JSON files for each article, structured as such:
[
{
"id": 1,
"title": "Test Title",
"author": "Test Author",
"disclaimer": "Test Disclaimer",
"body": "Test Body"
}
]
I am not sure if the id field is necessary but I saw it being used on a lot of JSON/Angular demos online so I thought I would include it as a unique identifier to each JSON file. Does anyone have any resources on how I can take these JSON files to create and format articles for my website? Any links to examples and resources would be helpful. I have been trying to find some but have had no luck. Thank you.
Well it up to you what all things you need to display. Your format looks good.
According to me following things need to maintained
Unique id
Title
author
Article itself
votes(if you are maintaining)
dateCreated
But any other schema will work as it varies application to application
Related
I have a generic medicine database in MongoDB, has about 3500 documents in it. I want to use medicine names and brand names in autocomplete input fields in the React web app.
The data might look like this:
{
"_id": {
"$oid": "5ed9bf1087263e1ef3d65288"
},
"name": "Ethamsylate + Mefenamic acid",
"brands": [
{
"name": "STOP-MF",
"package": "Tablet",
"strength": " ",
"price": "120.00"
},
{
"name": "SYLATE-M 500",
"package": "Tablet",
"strength": " ",
"price": "156.00"
},
],
}
Data will not change very often, so I want to cache it client-side right at the initial load.
I have been googling about this.
What I found is:
Making HTTP requests for each newly typed character is bad.
LocalStorage API is easy to use, but data will need to be compressed
IndexedDb offers unlimited storage, but the API is quite complex
I haven't found much about other storage options in the browser.
Thanks for any and all help!
Tried SWR, but it makes an HTTP request every time I reload the page, can't have that as the request takes 5-8 seconds to fetch data, I want to store data locally in browser somehow
have you try swr ? it may help you cache data at client side :D
Making HTTP requests for each newly typed character is bad.
It is not always bad, it depends on your use case. Would you say google search is badly implemented because it makes requests as you type? Not quite. You can also use throttle and debounce to somewhat limit amount of requests. But if you need offline access and your DB is relatively small then you have other options of course.
IndexedDb offers unlimited storage, but the API is quite complex
Have you tried to use some wrapper around it? Like maybe https://github.com/dfahlander/Dexie.js would fit for you?
I'm doing an app with angular since it's easy for me to make it work as a progressive web app, etc. In my app I have a blog section.
The problem is that I need to load a json files dynamically because I'm using it to make new post pages as entry blogs.
I need to know if i can create something like a folder named json and throw all my json files with the content of each post, keeping the angular parsing the folder and looking for new jsons while it's in run time. Or i must use a backend with some mongo or mysql bbdd?
You need to use backend to implement.
Try to receive the service response in JSON array as below:
{
"posts": [
{
"author": "Chinua Achebe",
"content": "abc"
},
{
"author": "Hans Christian Andersen",
"content": "def"
}
]
}
Just iterate over the posts array to display your posts
I want to send some encrypted json data from one ASP.NET MVC site to another, via the client accessing the site.
For example, a client clicks a link on site A, which then creates a unique Json object containing, perhaps, something like this:
var auth = { "name" : "John", "age" : "20", "data" : "abc" };
I want site B to be able to retrieve, decrypt, and read the data.
What I'm lost with, is I don't know how to send the data between the two sites. I've done lots of research into POST/GET, and none of what I've seen has been very clear with something as simple as sending a single json object between two sites.
So what I'm asking is two things, is there an easier way to go about this and does this seem like sound logic? And if you have any references or examples that I can use to better understand how to send data between sites, that'd also be very useful. Thank you.
sending data between two different sites is not as mushy as you think okay firstly if you are in development environment i.e., Visual Studio then you need to run both sites in two different insistences of visual studios by this you get addresses like
site a: localhost:5005/
site b: localhost:6012/
now if you are posting from site a to site b then your url will be like
localhost:6012/Home/Index.....
ie
$.post("localhost:6012/Home/Index",{auth:auth},successFunction);
I'm new to Grails, and I'm stuck on the basic structure of my web-app
So far I've implemented a Grails app that renders one JSON file to a readable table.
example
Given JSON file below
{
"abbreviation": "EXAMPLE",
"guid": "31ac235e2-3ad3-43e3-1fd4-41e6dfwegf03",
"metadata": {
"dataOrigin": "Example"
},
"rooms":
[
],
"site": {
"guid": "31ac235e2-3ad3-43e3-1fd4-41e6dfwegf03"
"title": "Example Testing"
}
}
My app renders above JSON file to below
Abbreviation : Example
GUID : 31ac235e2-3ad3-43e3-1fd4-41e6dfwegf03
Metadata : - DataOrigin : Example
Rooms : []
Site - GUID : 31ac235e2-3ad3-43e3-1fd4-41e6dfwegf03
Title : Exmaple Testing
Now, what should I do if I want my app to read JSON files with different Name/value pairs and renders it similarly to what my app does now?
(I've hard coded the application I have now)
I know this question is very vague, but can anyone give me any directions or insights on how to do this?
I'm afraid if there was a simply answer to this question then half of the web developers would be out of their jobs :-)
Anyway, there's probably several steps that could help in achieving your goal.
JSONSlurper(http://docs.groovy-lang.org/latest/html/gapi/groovy/json/JsonSlurper.html) to read JSON files. Obviously if you go for predefined structures you could use GSON (https://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/Gson.html) or similar library.
To display arbitrary data you can use the Grails Fields plugin(https://grails.org/plugin/fields).
I know it's all only pointers.
Suppose I have a few web forms to implement. The forms contain standard greetings, validation messages (e.g. "missing name", "email address is invalid"), errors (e.g. "temporary processing error"), etc.
Does it make sense to factor out all these text messages from the HTML and store it in an external text file so that non-technical people might edit the text ?
They say it is easier to edit text files instead of HTML. On the other hand I am afraid it would complicate the solution. What are the best practices in that field?
It depends from case. If texts are often edited by nontechnical people, it may make sense to move text into a separate file with simple structure. Otherwise, it indeed could complicate things.
Typically, server-side template engine is used to build pages from multiple different resources (such resources are, e.g., HTML-template files, database, configuration files, etc.). What type of resource and format of it to use is up to you and depends on situation. For example, you could store your error texts in JSON-format files like this:
{
"name" : {
"minlength" : {
"value": 2,
"error": "Name field must contain at least 2 characters"
},
"maxlength" : {
"value": 255,
"error": "Name field must contain not more than 255"
}
},
"email" : {
"pattern" : {
"value": "some_regexp_for_email_validation",
"error": "Please input a correct e-mail address"
}
}
}
In PHP in particular, JSON format can be read with json_decode() method.
An alternative to JSON is XML (though it's typically harder to use).
By the way, it may make sense to provide a web interface to edit form error rules and texts for nontechnical people. Then implementation details would be hidden from people who shouldn't know about them. So you could use whatever you want as for technical part of this while editors would see just a usable GUI with text fields.
You also may be interested in using ready server-side data-validation solutions like Zend Validator.
I'm using an java webapp which uses keys that mapped to strings in *.properties file.
I noticed that it's more difficult to support such code in cases you're searching "where's that field label "some cool field":
First you have to find key (ok, you get that key for that string is "submit.button.text"), and then you'll have to find where's key is actully used in your code.